1

I have three sections:

  1. Discography
  2. Performers
  3. Works

Within "Discography", a Matrix field contains related entries from "Performers" and from "Works".

I am looking to display those related entries in Discography with the code below, but nothing happens (no error, no display):

{% for entry in craft.entries.section('Discography').order('title') %}

    {{ entry.title }}

    {% for block in entry.discoOeuvres %}

        {% set relatedWorks = craft.entries.section('Works').relatedTo(entry) %}
        {% set relatedPerformers = craft.entries.section('Performers').relatedTo(entry) %}

        {% for work in relatedWorks %}
            {{ work.title }}

            {% for performer in relatedPerformers %}
                {{ performer.title }}
            {% endfor %}
        {% endfor %}
    {% endfor %}
{% endfor %}

Also tried to follow this solution, with no success...

Where do I miss something?

Thanks for helping.

  • I haven't dealt with this specifically, but I know that the relationship is with the matrix block and not the entry. Have you tried relatedTo(block)? (untested). The answer on the page you linked is also correct. – Douglas McDonald Oct 20 '14 at 16:41
3

As Douglas mentioned in the comments, if the relation is defined within a Matrix block, then the Matrix block is the source of the relation; not the entry.

Soy you just need to change relatedWorks and relatedPerformers to:

{% set relatedWorks = craft.entries.section('Works').relatedTo(block) %}
{% set relatedPerformers = craft.entries.section('Performers').relatedTo(block) %}

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.