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.

Parsing question

February 11, 2011 5:09pm

Subscribe [3]
  • #1 / Feb 11, 2011 5:09pm

    blg002

    59 posts

    Is code within a branch executed if it’s in a conditional that returns FALSE. I’m experience some major slowness from code that I don’t think should be being executed.

    For example:

    I’m on page page who’s URL only has a segment_1 (e.g. domain.com/reports/). In my template I have…

    {if segment_2}
      ...slow code…
    {if:else}
      ...
    {/if}

    If I remove everything between the first IF the page renders at a normal speed. This makes me think it is trying to execute that code, however what this code would output is not ever displayed. If I go to a page with the segment_2 it loads at a normal speed.


    EE 1.6.7 Build: 20090211

  • #2 / Feb 11, 2011 6:19pm

    Mark Bowen

    12637 posts

    I’m pretty sure that’s the way that advanced conditionals work because if you have an else then everything needs to be sort of stored so that it can check the first condition against the next and so on and so forth.

    One way that I’m fairly sure you might be able to get around that though is to place the ‘slow code’ into an embedded template and then it hopefully shouldn’t get embedded if the first condition isn’t true. This is due to the way that ExpressionEngine parses things. That or just use simple conditionals instead.

    So hopefully something like this would do what you need :

    Main Template

    {if segment_2}
    
    {embed="includes/slow-code"}
    
    {if:else}
    …
    {/if}

    Embedded Template (includes/slow-code)

    …slow code…

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Feb 11, 2011 7:04pm

    blg002

    59 posts

    Yep, that’s the ticket.

    I had definitely seen articles discussing this before, but one never fully grasps things until you have to deal with it.

    For future readers a fuller explanation can be found in the post Simple vs Complex Conditionals

  • #4 / Feb 11, 2011 8:37pm

    Mark Bowen

    12637 posts

    Yep, that’s the ticket.

    Excellent news. Glad that helped a bit.

    Best wishes,

    Mark

  • #5 / Feb 12, 2011 4:28pm

    Greg Salt

    3988 posts

    Hi blg002,

    Excellent. Glad that you got this sorted out.

    Cheers

    Greg

    @Mark, thanks for helping out.

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

ExpressionEngine News!

#eecms, #events, #releases