1

I have a channel entries tag which displays Videos and then a playa pair tag (coparents) which displays related videos based on a specific field.

Now, I would like to display other videos (let's say the last two entries of the "video" channel) in case no related videos are found. I tried with {if no_coparents}...{/if} but no luck so far since I don't manage to display video channel entries inside those tags.

{exp:channel:entries channel="video" url_title="{segment_3}" limit="1" status="open" transcribe="disable"}
  <h1>{title}</h1>
  {video_file}
  {video_description}

  <div class="block-related three columns">
    <h2 class="first-title">Related Videos</h2>
    {exp:playa:coparents channel="video" field="video_related_field" dynamic="no" limit="2"}
      <div>
        <h4>{title}</h4>
        <div>
          <a href="#">
            {if video_flickr_thumbnail}
            <img src="{video_flickr_thumbnail}" alt="{title}">
            {if:elseif video_thumbnail}
            <img src="{video_thumbnail}" alt="{title}">
            {/if}
          </a>
        </div>
      </div>
    {/exp:playa:coparents}

{!-- Now here I would like to get something in case there isn't any related video.
It would be great if I could just call {exp:channel:entries channel="video"}
to retrieve the last two videos. I tried with {if no_coparents} ... {/if}
but no luck so far. --}

  </div>
{/exp:channel:entries}
| improve this question | | | | |
1

Macxim - I just tested {if no_coparents} with great success here:

{exp:channel:entries limit="10"}
<h1>{title}</h1>
{exp:playa:coparents}
{if no_coparents}
no coparents
{/if}
parent entry id: {parent:entry_id}<br />
{/exp:playa:coparents}
{/exp:channel:entries}

Can I ask you to try this code in a template and see what results you get? Just copy/paste the above into a template. You may need a few recent tests with coparents and without. I made this as minimal as possible to test it.

Please let me know if that helps!

| improve this answer | | | | |
  • Hello Lisa, thank your for your answer. Unfortunately, still no luck with that. no coparents was displayed even if the entry did have coparents. – Macxim Mar 20 '13 at 11:11
  • You tried with the exact code, and nothing else, Macxim? It may be time for me to login and have a look. Is that possible? If so, please email super admin details to support@pixelandtonic.com, and reference this thread. Thank you! – Lisa Mar 20 '13 at 17:48
0

You'll have to embed your alternative Channel Entries loop in this case.

{exp:playa:coparents channel="video" field="video_related_field" dynamic="no" limit="2"}
    <!-- snip -->
    {if no_coparents}
        {embed="videos/_related"}
    {/if}
{/exp:playa:coparents}
| improve this answer | | | | |
  • I was afraid someone would answer this. Isn't there any other option? Would a snippet do the thing? – Macxim Mar 7 '13 at 8:05
  • Just to be sure, {if no_coparents}...{/if} has to be inside the {exp:playa:coparents} loop? Just asking because it is not currently working. The content of {if no_coparents} appears even if there is coparents. Weird. – Macxim Mar 7 '13 at 9:26
  • Yes, the conditional has to be inside the playa:coparents tag. A snippet will not work, as it's just replaced before parsing. The issue is that you would be nesting a channel:entries tag inside another channel:entries tag, causing massive variable collision. An embed is the way to go. – Derek Hogue Mar 7 '13 at 14:12
  • Do you have any clue about why the {if no_coparents}...{/if} is not working? I even checked with {exp:playa:total_coparents}, but the {if no_parents} is completely ignored, the content shows up, no matter what. – Macxim Mar 7 '13 at 14:47
  • Try with something simple, like {if no_coparents}There were no co-parents.{/if}. – Derek Hogue Mar 7 '13 at 14:52

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.