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} 
  • Did you try my variation below? – stuartmcd69 Jan 22 '15 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 Jan 22 '15 at 21:55
  • You'll have to prefix the subsequent tags as well… {if my_var:count =='1'} Code updated below. – stuartmcd69 Jan 23 '15 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 Jan 23 '15 at 18:16
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

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

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.