0

I have a list that builds based on the URL segment. Sometimes there no entries for the segment and need to display "no results". I have tried several varations on this and nothing seems to work.

Any suggestions are greatly appriciated, thanks for looking.

I have tried to take this another direction and am tying to use {if no_parents} … {/if} variable.

However written like this it only shows up when there are results not when there is no results. Here is what my code looks like now

{exp:channel:entries 
   channel="my_child_channel"
   orderby="data_contact_last_name"
   sort="asc" 
   limit="3"
   }

     {exp:playa:parents 
     channel="mychannel" 
     field="my_field"
     var_prefix="my_var"
     }


        {if no_parents} no parent content {/if} 

        <!-- label -->  
        {if count == '1'} 
         <h4 class="f400m"><strong>{child:title}</strong></h4>  <!-- The title-->
        {/if}

            <h4><a href="{my_var:url_title}">{my_var:title}</a></h4>

   {/exp:playa:parents}

Earlier I tried this and what Jason suggested i also could not get to work.

{exp:channel:entries 
   channel="my_channel" 
   limit="3"
   }

   {exp:playa:parents 
      channel="my_parent_channel" 
      field="field_choice" 
      require_entry="yes"}

{if no_results}  <p>There are no entries available.</p>  {/if}

     {if count == '1'} 
         <h4>{child:title}</h4>
      {/if}

       <h4><a href="{url_title}">{title}</a></h4>

 {/exp:playa:parents}
{/exp:channel:entries} 
4
  • Did you try my variation below? Commented Jan 22, 2015 at 5:18
  • Yes I did and it does not display the message and breaks my {if count == '1'}<h4><a href="{url_title}">{title}</a></h4>{/if}. Now I needed add the var_prefix anyway and have been busy trying to get the original child to work for that purpose. It was recommended I use {if no_parents} by Anris but I can't get that to work either.
    – Eric
    Commented Jan 22, 2015 at 21:55
  • You'll have to prefix the subsequent tags as well… {if my_var:count =='1'} Code updated below. Commented Jan 23, 2015 at 0:10
  • Does not work, then no title label shows up at all. Tried a couple of variations. There has to be some way to get this work. Thanks for looking, anything else you might have is greatly appreciated!
    – Eric
    Commented Jan 23, 2015 at 18:16

1 Answer 1

1

The if no_results is actually referencing the outer exp:channel:entries tag - basically an EE parse order issue.

To test inside playa, you need to use the var_prefix parameter... as in:

{exp:playa:parents var_prefix="my_var"}
{if my_var:no_results}
    //no results behaviour here
{/if}
{if my_var:count == '1'} 
     <h4 class="f400m"><strong>{child:title}</strong></h4>  <!-- The Str Discipline title-->
{/if}
{/exp:playa:parents}

The docs: https://docs.pixelandtonic.com/playa/templating/module/parents.html

1
  • Or as a simplier solution, just make sure you also have {if no_results}no entry to display {/if} for channel entries tag. Commented Jan 23, 2015 at 10:11

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.