2

I'm trying to pull through content based on items within a SuperTable entries field.

After searching around I currently have this:

{% set individuals = craft.entries({section: 'barristers', relatedTo: { targetElement: entry, field: 'specialisms.linkToPage'}}) %}
{% for entry in individuals %}
  {{ entry.title }}

But it's not pulling anything through?

Any help appreciated

Thanks

1
  • If entry is the entry with the Super Table field it is the sourceElement of that relation not the targetElement.
    – carlcs
    Commented Oct 27, 2015 at 12:44

1 Answer 1

5

Unfortunately, you can't use Craft's built in relations service for reverse relations lookup with Super Table. This is because there's actually a special case for nested relations, such as a Matrix field. Craft's own relations service has special handling for Matrix fields, which we also need to make use of.

Fortunately, Josh Angell (the star that he is) has submitted a fix for this, without having to hack the core. You'll just need to alter your code to use the following:

{% set reverseRelatedElements = craft.supertable.getRelatedElements({
  relatedTo: {
    targetElement: entry,
    field: 'specialisms.linkToPage'
  },
  section: 'barristers'
}) %}

{% for relatedEntry in reverseRelatedElements %}
  {{ relatedEntry.title }}
{% endfor %}
6
  • 1
    @crawf, do you know if there is a way to do a similar thing if the super table in question sits within a matrix block?
    – Mike Vaux
    Commented Apr 13, 2016 at 17:56
  • 1
    @MikeVaux did you ever work out if there is a way for ST in Matrix? Commented Nov 17, 2016 at 15:46
  • 1
    I'm trying to also get this working for an ST in a Matrix. Did anyone get it going? Commented Jan 10, 2017 at 14:55
  • 1
    @richardpixel Any luck? I am stuck on this as well. Commented Feb 3, 2017 at 7:17
  • 1
    @DanielleLeComte Nope. I ended up swapping to Neo. Had similar issues but Benjamin sorted me out. Commented Feb 3, 2017 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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