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

You have an invalid conditional in your template. .. Which one?

Developer Preview

Kurt Deutscher's avatar
Kurt Deutscher
827 posts
11 years ago
Kurt Deutscher's avatar Kurt Deutscher
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 { expected ENDIF.

After reading up on all the changes to how conditionals work in 2.9.0 I thought I would be wise to update an existing/fully functional site (one we use for testing) and see how this might effect us.

It appears that the new way of doing things isn’t backwards compatible at the moment.

We’ve been greeted with this error that really doesn’t do much to tell us what template we should be looking in.

So I’m wondering if there’s any way within EE’s Template Engine to search and locate the offending conditional so we can update it to the new format?

In site’s using pretty DRY development methods, and where a single page might include over a dozen snippets and/or embeds and such, it can take a while to hunt down the needle(s) in the haystack.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
11 years ago
Pascal Kriete's avatar Pascal Kriete

It sounds like you’re hitting the bug that Low caught this thread. I’ve attached a patched file there, but I expect we will also have another preview soon. Sorry for the instability.

It does bring up a very good point though, we should have a way of tracking where things come from. File locations would be nice and line numbers would be the panacea. We’ll look into it for sure!

       
Sobral's avatar
Sobral
87 posts
11 years ago
Sobral's avatar Sobral

@Pascal, the snippets can make hard to find the real line numbers of an error, so may I suggest you to show more info about the conditional itself? Maybe the first part of it? Is it possible?

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
11 years ago
Pascal Kriete's avatar Pascal Kriete

Oh when I say find the file, I definitely mean find the source file. So the name of the snippet if it’s in a snippet. But yes, we could try to do a mysql-esque error output “You have an error near ‘{if [exp;] == …’”.

The progressive buildup of the templates makes both the line numbers and the source code difficult since it changes during execution.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
11 years ago
Pascal Kriete's avatar Pascal Kriete

Should have much more accurate error reporting in the latest release. Thanks for the feedback, guys!

       
Kurt Deutscher's avatar
Kurt Deutscher
827 posts
11 years ago
Kurt Deutscher's avatar Kurt Deutscher

Finally having a moment to try out the latest build and things are looking better:

Parser State: Unexpected ‘}’ (RD); expected ENDIF tag in Template “site_system/index” on line 306.

The only issue now is that this template only has 26 lines total.

So I’m guessing that the issue is within one of a possible 8 different embedded templates (used conditionally, based on the URI). When some combination of the 8 embeds is used, then this template must end up with 306 lines or more.

Thanks for the work on this up to this point, if there’s anyway to narrow things down to the actual template, or the line number at which the actual template is embedded, then this would be much, much more helpful.

       
Sobral's avatar
Sobral
87 posts
11 years ago
Sobral's avatar Sobral

Try to count the lines of the snippets too.

       
Derek Jones's avatar
Derek Jones
7,561 posts
11 years ago
Derek Jones's avatar Derek Jones

Hey Kurt, I get the actual line of the actual resource when I introduce a conditionals error. For example, if I put this conditional in various locations:

{if something so{/if}

Then I get these errors depending on where I’ve placed it:

Parser State: Unexpected ‘so’ (VARIABLE); expected RD in Snippet “snp-test” on line 1
Parser State: Unexpected ‘so’ (VARIABLE); expected RD in Template “default/embed” on line 5.

So if it were a conditional on the embedded template, it should indicate the embedded template name and line. How is site_system/index being built? Do you have PHP enabled and pulling anything in that way?

       
Kurt Deutscher's avatar
Kurt Deutscher
827 posts
11 years ago
Kurt Deutscher's avatar Kurt Deutscher

No PHP,

This is the template:

{preload_replace:preload_language="{embed:display_language}"}
{if segment_1 == 'site_system'}
 {redirect='404'}

{if:elseif segment_1 == 'print'}
 {embed='site_display/header_html' {snippet_dynamic_variables}}
 {embed='site_display/print' {snippet_dynamic_variables}}

{if:elseif segment_1 != '' AND '{embed:404}' == '404'}
 {redirect='404'}

{if:else}
  {embed='site_display/header_html'  {snippet_dynamic_variables}}
  {embed='site_display/header' {snippet_dynamic_variables}}
 {if segment_3}{!-- SINGLE ENTRY PAGE --}
  {embed='site_display/single_entry' {snippet_dynamic_variables}}
 {/if}
 {if (segment_1 OR segment_2) AND segment_3 == ''}{!-- LANDING AND CATEGORY PAGE --}
  {embed='site_display/category' {snippet_dynamic_variables}}
 {/if}
 {if segment_1 == ''}{!-- HOME PAGE --}
  {embed='site_display/home' {snippet_dynamic_variables}}
 {/if}
  {embed='site_display/footer' {snippet_dynamic_variables}}

{/if}{!-- SEGMENT_2 CATEGORY MATCH CHECK -- 404 --}

And I can reduce it down to this and the two embedded templates load:

{preload_replace:preload_language="{embed:display_language}"}

 {embed='site_display/header_html'}
 

 {embed='site_display/footer'}

But this wont fly, and the interesting part is that it wont fly even when the /header template is totally empty:

{preload_replace:preload_language="{embed:display_language}"}

 {embed='site_display/header_html'}
 {embed='site_display/header'}
 {embed='site_display/footer'}

So I’m scratching my head big time on this one.

       
Derek Jones's avatar
Derek Jones
7,561 posts
11 years ago
Derek Jones's avatar Derek Jones

Are these templates saved as files, Kurt? If so, I’d love to have a copy in a zip file so I can tinker directly.

       
Kurt Deutscher's avatar
Kurt Deutscher
827 posts
11 years ago
Kurt Deutscher's avatar Kurt Deutscher

Give me a few moments, and I’ll pack something up for you.

Hm…. well “export all” in the template manager (first time I’ve ever tried it) create an unzipp-able zip. … reminds me of someone’s “unblock-able move”.

… and same with export group.

So let me do this another way.

       

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.