ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

2.9.0 bug? Or Conditionals parse order change?

August 16, 2014 8:09am

Subscribe [3]
  • #1 / Aug 16, 2014 8:09am

    Rick Lecoat

    128 posts

    Hi; I’ve got a bunch of templates that all use the same snippet, combined with a preload_replace variable, to provide a lighter-weight alternative to embedded templates (as described here). Prior to EE 2.9.0 it was working perfectly, but now the template throws an error, because the snippet contains nested Conditionals which are are evaluating before the preload_replacement has been carried out (previously the conditionals—or least some of them—were evaluating after the preload_replacement, because they are what used to be considered Advanced Conditionals).

    My question is this: is this expected behaviour brought about by the change in conditional parsing in 2.9.0, or is it a bug? And if it’s expected behaviour then is there any way around it (other than using an embed)?

    Here is the relevant portion of the code (the rest of the template is pretty mundane)—both the channel:entries loop that references the snippet, and the snippet itself.

    Channel:entries loop:

    {exp:channel:entries channel="news"}
     {!-- ...some other fields… --}
     {preload_replace:pre_gridfield="name_of_grid_field"}
     {snp_gridfield_output}
     {!-- ...some more fields… --}
    {/exp:channel:entries}

    Snippet (named snp_gridfield_output):

    {{pre_gridfield}}
     {exp:typogrify:widont}{{pre_gridfield}:text}{/exp:typogrify:widont}
     {if {pre_gridfield}:image}
         {if {pre_gridfield}:caption != "" || {pre_gridfield}:credit != ""}
       <figure>
        {if {ress}  480}{{pre_gridfield}:image:mobilesize}{if:else}{{pre_gridfield}:image}{/if}
        <figcaption>{{pre_gridfield}:caption}<span>{if {pre_gridfield}:credit != "" && {pre_gridfield}:caption != ""} / {/if}{if {pre_gridfield}:credit}© {{pre_gridfield}:credit}{/if}</span></figcaption>
       </figure>
         {if:else}
       {if {ress}  480}{{pre_gridfield}:image:mobilesize}{if:else}{{pre_gridfield}:image}{/if}
         {/if}
     {/if}
    {/{pre_gridfield}}

    There are lots of nested conditionals in that snippet, but the one that seems to be throwing the template error is the outermost one. The error page displayed reads:

    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 ‘image’ (VARIABLE); expected RD in Snippet “snp_gridfield_output” on line 3.

    Thanks in advance for any insight into whether this is a bug or simply an expected consequence of the new conditionals. (NB. I’ve also posted this problem over at Stackexchange).

  • #2 / Aug 19, 2014 2:31pm

    mkinberg

    4 posts

    I recently had the same problem.  Through the process of elimination I discovered it was an apostrophe in my Entry that was causing this error to happen.

    i.e.

    {if '{cancerstreated_sec1_studies}{cancerstreated_sec1_studies:medicalprof_sec1b_title}{/cancerstreated_sec1_studies}'!=''}
         <div class="twelveRightSection">
          <div class="topTitle">
           Related Studies
          </div>
          <div class="bottomTable">
           <table class="relatedStudies">
            {cancerstreated_sec1_studies}
            <tr class="{cancerstreated_sec1_studies:switch='|oddRow'}">
             <td class="studyName">{cancerstreated_sec1_studies:medicalprof_sec1b_title}</td>
             <td class="studyAuthor">{cancerstreated_sec1_studies:medicalprof_sec1b_author}</td>
             <td class="studyCTA"><a href="http://{cancerstreated_sec1_studies:medicalprof_sec1b_url}" title="Read Story" target="_blank" rel="noopener">Read Study</a></td>
            </tr>
            {/cancerstreated_sec1_studies}
           </table>
          </div>
         </div>
         {/if}


    I was using an IF to check if the following Grid field existed.  IF it existed, show the content. {cancerstreated_sec1_studies:medicalprof_sec1b_title}

    By removing the apostrophe from my entries title name, the error went away.  I’m now checking for the Author’s name instead of the entry title for this conditional.  Not ideal, but it works.

    in EE V2.9 Grid has been such a headache… 

    I hope this helped!

  • #3 / Aug 20, 2014 2:11pm

    stefanos

    61 posts

    It seems with EE2.9 the conditionnals commands are more strict.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases