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

  • If entry is the entry with the Super Table field it is the sourceElement of that relation not the targetElement. – carlcs Oct 27 '15 at 12:44
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 %}
| improve this answer | |
  • @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 Apr 13 '16 at 17:56
  • @MikeVaux did you ever work out if there is a way for ST in Matrix? – Josh Angell Nov 17 '16 at 15:46
  • @JoshAngell No, afraid not. I didn't look into it in any great depth though. – Mike Vaux Nov 17 '16 at 17:13
  • I'm trying to also get this working for an ST in a Matrix. Did anyone get it going? – richardpixel Jan 10 '17 at 14:55
  • @richardpixel Any luck? I am stuck on this as well. – Danielle LeComte Feb 3 '17 at 7:17

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.