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!
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.
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!
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.
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…
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.