1

Simple question here hopefully.

I have an album page that displays a track listing. With the option for up to 4 discs being displayed as show below.

DISC 1

Track listing

DISC 2

Track listing

DISC 3

Track listing

DISC 4

Track listing

Here is my EE code

{exp:channel:entries channel="disco" status="open" orderby="disco_release_date" sort="desc" limit="1"}

<div class="disc-tracks">

    {disco_disc2_tracks}

    <li><h4>{disco_disc2_tracks:title}</h4>
    {!--IF STATEMENT SHOWS THE DUET PARTNER AND HIDES THE (WITH) IF THERE ISN'T ONE--}
    <p>{if disco_disc2_tracks:track_duet_partner}<em>(with {disco_disc2_tracks:track_duet_partner})</em>{/if}</p>
    <p><span class="songwrittenby">Written By: {disco_disc2_tracks:track_writtenby}</span></p></li>

{/disco_disc2_tracks}

</div></ol><!-- END DISCOGRAPY DISC 2 TRACKS -->

{/exp:channel:entries}

I have 4 of those on the page. 1 for every disc I want to wrap everyone in an IF statement so that if no tracks are selected on the channel entries page for a specific disc aka that disc has 0 tracks selected - that it doesn't show the header "Disc 2" "Disc 3" "Disc 4" and have empty titles on my page. I have an IF statement for the duet partner already in my code above and it works great, but I can't seem to write one that can hide the whole header and div containing the Disc # and tracks.

Also the tracks are a relationship filed and I'm pulling them from another channel. See image

How I select tracks for each disc in EE

0

Ok that's simple enough. The relationship field loop is just like the entries loop. It shouldn't return anything if there isn't anything to grab. But regardless, all you should have to do is wrap your heading in a conditional and have it only display before the first returned entry from the related channel, like this:

{disco_disc2_tracks}
{if disco_disc2_tracks:count == "1"}
<div class="disc-tracks">
DISK 2 (you didn't include your header but I'm assuming you have something like this going on prior to the related entries loop.)
<ol>{!-- START DISCOGRAPHY --}
{/if}
<li><h4>{disco_disc2_tracks:title}</h4>
{!--IF STATEMENT SHOWS THE DUET PARTNER AND HIDES THE (WITH) IF THERE ISN'T ONE--}
{if disco_disc2_tracks:track_duet_partner}<p><em>(with {disco_disc2_tracks:track_duet_partner})</em></p>{/if}
<p><span class="songwrittenby">Written By:         {disco_disc2_tracks:track_writtenby}</span></p></li>

{if disco_disc2_tracks:count == disco_disc2_tracks:total_results}</ol></div>{/if}
  {/disco_disc2_tracks}

So the idea is start the div and the list on condition that at least one entry is returned by count by the related entries loop (for each disk) and close it on condition that the returned entry by count is the last returned entry. I also recommend moving the markup around the track duet partner INSIDE the conditional as well - otherwise you would have paragraph tags (empty) when one doesn't exist.

| improve this answer | |
  • Awesome, that worked perfect! Thanks so much. – Kevin Mar 12 '15 at 21:50
0

Maybe this works, wrap your code around this. It then should say if my_field "disco_disc2_tracks" is NOT empty then show stuf.. If empty do not show stuff.

{if disco_disc2_tracks != ""}....{/if}

{if disco_disc2_tracks != ""}

{disco_disc2_tracks}

<li><h4>{disco_disc2_tracks:title}</h4>
{!--IF STATEMENT SHOWS THE DUET PARTNER AND HIDES THE (WITH) IF THERE ISN'T ONE--}
<p>{if disco_disc2_tracks:track_duet_partner}<em>(with {disco_disc2_tracks:track_duet_partner})</em>{/if}</p>
<p><span class="songwrittenby">Written By: {disco_disc2_tracks:track_writtenby}</span></p></li>

{/disco_disc2_tracks}

{/if}

| improve this answer | |
  • That didn't work. It does the same thing and just hides it regardless if there is a track on a specific disc or not. – Kevin Mar 6 '15 at 23:21
  • Maybe it doesn't do anything because of the relationship field is addressed properly you can try my conditional with {if disco_disc2_tracks:title != ""}....{/if}! But the count solution which Jean mentioned should work as well i presume. – Dave_Daliz Mar 9 '15 at 9:42

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.