2

Can EE multiple relationship fields be displayed nested? I'm not able to get this working, and it's not clear from the Relationships docs page if it's supposed to.

Say I have 3 channels -- bands, albums and songs -- and my relationship fields are top-down rather than bottom-up, ie, bands have a multiple relationship field of albums, and albums have a multiple relationship field of songs. I want to display a list of bands, and within each band its albums, and within each album its songs. In the following example, songs do not appear:

<ul>
    {exp:channel:entries channel="bands"}
    <li> 
        {title}
        <ul>
            {bands_albums}
            <li>
                {bands_albums:title}
                <ul>
                    {bands_albums:albums_songs}
                    <li>
                        {bands_albums:albums_songs:title}
                    <li>
                    {/bands_albums:albums_songs}
                </ul>
            </li>
            {/bands_albums}
        </ul>
    </li>
    {/exp:channel:entries}
</ul>

I can get a single song from each album to appear by removing the inner loop:

<ul>
    {exp:channel:entries channel="bands"}
    <li> 
        {title}
        <ul>
            {bands_albums}
            <li>
                {bands_albums:title}
                <ul>
                    <li>
                        {bands_albums:albums_songs:title}
                    <li>
                </ul>
            </li>
            {/bands_albums}
        </ul>
    </li>
    {/exp:channel:entries}
</ul>

But I need all the songs.

2
  • On the innermost tag, have you tried it as {albums_songs:title} instead of {bands_albums:albums_songs:title} ? Commented Oct 24, 2014 at 12:49
  • Thanks for the suggestion. Just tried it and it doesn't do anything. Has it worked for you?
    – Adam Khan
    Commented Oct 25, 2014 at 21:31

2 Answers 2

1

Off the top of my head, I think I've done this successfully before... Maybe try using the parents or children tag in conjunction with a channel parameter like this:

<ul>
  {exp:channel:entries channel="bands"}
   <li> 
    {title}
    <ul>
        {bands_albums}
        <li>
            {bands_albums:title}
            <ul>
                {bands_albums:parents channel="songs"}
                  <li>
                     {bands_albums:parents:title}  
                  <li>
                {/bands_albums:parents}
            </ul>
        </li>
        {/bands_albums}
    </ul>
   </li>
  {/exp:channel:entries}
</ul>
1

Yes, they should be nestable. I have the following code working - all the relationships are within one channel. I built it as a way to see if relationships could be used intra-channel to build navigation:

<h2>The Family Tree from the Top Down </h2>
{exp:channel:entries channel="people" disable="member_data|pagination|categories"}

  {if count==1} {!-- start the top-level unordered list --}
    <ul>
  {/if}

    {parents field="offspring"}
        {if parents:no_results} {!-- entries with no parents are top-level --}
            <li>
              {title}
              {offspring} {!-- second level entries --}

                {if offspring:count == 1}<ul>{/if} {!-- open the second-level unordered list --}

                    <li>
                      {offspring:title}
                      {offspring:offspring} {!-- third level entries --}

                        {if offspring:offspring:count == 1}
                          <ul> {!-- open 3rd level list --}
                        {/if}

                        <li>{offspring:offspring:title}</li>

                        {if offspring:offspring:count==offspring:offspring:total_results}
                          </ul> {!-- close third-level list --}
                        {/if}

                      {/offspring:offspring}
                    </li>

                {if offspring:count==offspring:total_results}
                  </ul> {!-- close second-level list --}
                {/if}

              {/offspring}
            </li>
        {/if}
    {/parents}

    {if count==total_results}
      </ul> {!-- close top-level list --}
    {/if}
{/exp:channel:entries} 

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.