We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

{if parents:no_results} causing errors?

Development and Programming

eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

Hi, I’m trying to use {if parents:no_results}, but when I add it to my template I get this error:

“You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

Parser State: Unexpected end of Template “projects/detail” on line 74; expected ENDIF tag for opening on line 58.”

I’m not seeing any issues with the conditionals, but maybe I’m missing something.

Here’s the code, with comments on the lines called out in the error:

{parents orderby="url_title" sort="asc"}
    {if parents:no_results}
     <div id="project-media" class="row no-margin">
     {if supporting_media && supporting_is_small != "True"} {!-- LINE 58 --}
      <div class="col-md-7 col-md-offset-1 align-right">
       <div class="supporting">
        {supporting_media}<br><br>
       </div>
      </div>
     {if:else}
      <div class="col-md-7 col-md-offset-1 align-right"></div>
      <div class="col-md-4">
      {if supporting_media && supporting_is_small == "True"}
       <div class="supporting">
        {supporting_media}<br><br>
       </div>
      {/if}
      </div>
     {/if}
     </div> {!-- LINE 74 --}
    {if:else}
        {!-- more stuff --}
    {/if}
   {/parents}

Thanks!

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

It’s complex enough it’s hard to debug- though I’m not seeing any syntax errors.

I’d start in a test template and simplify.

{parents orderby="url_title" sort="asc"}
    {if parents:no_results}
     
     {if supporting_media != ''} 
      sm:  {supporting_media}

     {if:else}
      no sm
     {/if}
   {/if}
{title}

{/parents}

But get it to the simplest thing that errors and really, really shouldn’t.

And make sure you’re on the latest version.

       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

OK, here goes:

{parents orderby="url_title" sort="asc"}
    {if parents:no_results}
     {if title}
      {if title}
      {/if}
     {/if}
    {/if}
   {/parents}

This results in a literal {/if} being output to the page as many times as the item has parents. It only happens if there are two nested conditionals inside {if parents:no_results}. It’s like an extra {/if} is being included somehow.

I’m on version 5.2.4.

Thanks for the help!

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

It’s starting to look like a bug, probably related to the no_results handling. I get the stray closing if with this:

{exp:channel:entries channel="blog"}

<h1>{title}</h1>

 
    {if no_results}
    nope: 
      {if title}
       {if entry_id}
    {title}
       {/if}
      {/if}
    {/if}

{/exp:channel:entries}

So it’s not just relationships.

I’m poking to see if I can figure out a solution.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

OK, see if this works instead of no_results tag, try the parents:total_results tag instead, outside of the tag pair.

That do it?

       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

So, if I do this:

{parents orderby="url_title" sort="asc"}
 {if parents:total_results == 0}
  {if title}
   {if title}
   {/if}
  {/if}
 {/if}
{/parents}

No more error, but the code inside the conditional also isn’t executed if total_results == 0 (since the loop doesn’t happen at all). Let me know if I’m misunderstanding what you were suggesting…

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

Ah- sorry. Move it outside of the parent tags. That one can stand on its own- in part because it’s a useful conditional.

So outside of the parent tag:

{if parents:total_results == 0}nada{/if}
       
eloyer17's avatar
eloyer17
8 posts
5 years ago
eloyer17's avatar eloyer17

Aha–yes that does it! Thanks for your help.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
5 years ago
Robin Sowell's avatar Robin Sowell

Nice! And thanks for the confirmation. With the level of conditionals, the best option is to move them out of that no results tag.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.