1

A year ago I asked this question and thanks to the answers I got things working. A year later and i'm trying to do the same thing on a different website... only this time it's not working!

  • Section Handle = artist
  • SuperTable Field Handle = lineUp
  • SuperTable 'Entry' Field = artistPerforming, which is linked to Section 'artist'

Here's my code:

{% set reverseRelatedElements = craft.supertable.getRelatedElements({
    relatedTo: {
        targetElement: entry,
        field: 'lineUp.artistPerforming'
    },
    section: 'artist'
}) %}

{% for eventLineUp in reverseRelatedElements %}
    {{ eventLineUp.title }}
{% endfor %}

My SuperTable field is assigned to a Section with handle stageEvent, so from my stageEvent entry i'm trying to pull related entry information from Section artist.

Nothing is outputting but I don't get any errors??

Can anyone see what i'm doing wrong?

Many thanks

Martin

1

You can’t use this special Twig function to get reverse related entries at all, as you’re not dealing with reverse relations in that context.

From a stageEvent entry you can just loop through the Super Table rows and get the related artist entry like so:

{% for row in entry.lineUp %}
    {% set artistPerforming = row.artistPerforming.first() %}

    {% if artistPerforming %}
        {{ artistPerforming.title }}
    {% endif %}
{% endfor %}
0

I'm not sure if there was an update that made this possible, but OPs code worked for me (Craft v3.0.25). Just note that when calling Super Table, it has to be camel case like so ...craft.superTable.getRelatedElements...

My version:

{% set relatedMovies = craft.superTable.getRelatedElements({
    relatedTo: {
      targetElement: entry,
      field: 'roles.actor'
    },
    section: 'movies'
}) %}

I am calling this inside of an 'actor' entry template which is referenced here: targetElement: entry. Inside the actor template, I want to list all of the movies that the actor was in, hence section: 'movies'. Inside the movie entry, the actor is referenced inside a Super Table field ('roles') with a row handle of 'actor'.

Calling the following produces a list of all the movies the actor has been in.

{% for movie in relatedMovies %}
  <p>{{movie.title}}</p>
{% endfor %} 

I hope this helps someone that comes across a similar issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.