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.

Snippets and conditionals: Parse order?

July 06, 2011 10:06am

Subscribe [2]
  • #1 / Jul 06, 2011 10:06am

    ira42

    167 posts

    Hey there,

    I’m running EE 2.2.1,  and have one template which is conditionally pulling in one of several snippets,  depending on different factors.  For example,  the template looks something like:

    ...
    
    {if segment_1 == "products"}{snippet_one}{/if}
    {if segment_1 == "services"}{snippet_two}{/if}
    {if channel == "MyChannel"}{snippet_three}{/if}
    
    ...

    For weeks,  this has seemingly worked just fine,  and it only displays the proper snippet based on the conditionals.

    However,  I was just adding some javascript to one of my snippets,  and had an error in my syntax,  which broke the rendering of that page.  The thing is,  it produced the same error on ALL of the pages using this template,  even those that weren’t calling that one bad snippet.

    This leads me to believe that regardless of the conditionals above,  it’s at least reading ALL of the snippets,  even if it’s not showing them…

    Any clarification on the parse order between snippets and their surrounding conditionals?

    Tx!

  • #2 / Jul 07, 2011 5:08am

    John Henry Donovan

    12339 posts

    ira42,

    When did you install EE2.2.1? There are some hotfixes which were released on the 5th which fixed broken js

    Can you apply that and see if the behaviour still persists

    Snippets are called before simple conditionals

    Here’s a good pdf on the Parse Order of EE

  • #3 / Jul 07, 2011 10:27am

    ira42

    167 posts

    Thanks, I think I’ve tracked it down to an issue with a 3rd party addon (Snippet Sync).

    It’s probably a similar issue to the one fixed by the hotfix.  Snippet Sync reads snippet files in the filesystem and syncs them to the db,  but ONLY if you’re logged in as a super admin, or if debugging is set to 1 or 2.  What was happening is that I WAS logged in but then the EE login timed out after a few hours,  and it wasn’t able to sync.  (I think)

    I will follow up with the addon developer,  because I am still occasionally getting the following EE error, when EE logs me out (after hotfix as well):

    Unable to load requested field type file: ft..php.

    And thanks for the PDF about parse order!  Very handy.  This was also discussed in the EE Weekly Chat last night.  We determined the same,  that ALL of the Snippets will be parsed, before the conditionals decide whether or not to display them. 

    But if I understand this correctly,  even though the snippets are parsed first,  the module and plugin tags within them will still only be run,  if the surrounding conditional returns true?

  • #4 / Jul 07, 2011 10:57am

    ira42

    167 posts

    Oh,  and let me just say what a JOY it was,  to be able to download a Hotfix,  with just the required (modified) files.  It’s a simple change to the hotfix distribution,  but makes a HUGE difference.  Yay!

  • #5 / Jul 12, 2011 7:39pm

    Lisa Wess

    20502 posts

    Hi, ira42,

    Essentially, snippets are intended to be parsed as they are encountered, exactly as if they were directly there in the template instead of a snippet.  That is how you should approach them when optimizing your site. 

    Att his point, are you all fixed up and working? Did your addon dev help you fix that ft..php issue?

    Thanks!

  • #6 / Jul 12, 2011 8:03pm

    ira42

    167 posts

    Hey Lisa,

    Actually,  I haven’t encountered the error in a while,  (but I haven’t worked on that site too often lately either).

    I think it’s safe to close this.  If it crops up again,  I can follow up with the addon dev.

    Cheers

  • #7 / Jul 12, 2011 8:24pm

    Lisa Wess

    20502 posts

    Awesome, Ira!  You know where we are if you need help. Thank you =)

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

ExpressionEngine News!

#eecms, #events, #releases