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.

EE parses code when it shouldn't, resulting in a long loading time..

September 13, 2011 6:02am

Subscribe [4]
  • #1 / Sep 13, 2011 6:02am

    I’m working on a “real property” site that does the following:


    Check the page URL, if segment 2 is empty, show the overview page, if not, show the detail page.
    The Overview page shows all the buildings ( title + thumb ) the detail page shows all the info about 1 building ( title, gallery, etc.. )


    This is roughly the code I’m using:

    {if segment_2 == ""}
       {exp:channel:entries channel="gebouwen"}     
          <a href="http://{lang_url}gebouwen/{url_title}">{title}</a>      
          {exp:ce_img:single src="{preview_image}" max_width="167" max_height="218" crop="yes|center,top" filter="sharpen,130"}
       {/exp:channel:entries}
    {if:else}
       {exp:channel:entries channel="gebouwen"}
          {title}
          {gallery}
             {exp:ce_img:pair src="{image}" max_width="927" max_height="345" crop="yes|center,center" filter="sharpen,100"}
                {made}
             {/exp:ce_img:pair}
          {/gallery}
       {/exp:channel:entries}
    {/if}


    Now, this works, no problem, but I noticed the page loads very slowly.
    upon further investigation I discovered that when showing the overview page, ( and segment 2 = empty )
    EE still parses the second part in my if-statement
    and loads ALL the images in the galleries of ALL my entries. Resulting in a 11MB page. ( no wonder it took a while to load )


    So, why is this part being parsed:

    {gallery}
         {exp:ce_img:pair src="{image}" max_width="927" max_height="345" crop="yes|center,center" filter="sharpen,100"}
            {made}
         {/exp:ce_img:pair}
      {/gallery}

    when the segment_2 == “”  ?

  • #2 / Sep 13, 2011 6:40am

    aelvan

    33 posts

    Could it be that you haven’t closed the {gallery} tag properly? Not closing properly has given me many strange EE moments… 😉

  • #3 / Sep 13, 2011 6:44am

    aelvan

    33 posts

    Reading your post again, I see that I may have misunderstood the problem… or not. Are the images actually being output to the html, or is the 11MB the memory consumption? If the latter, as I’ve understood it, EE parses the tags in all conditions, then removes the result in the condition that isn’t matched. To counter this you should consider using SwitchEE (http://devot-ee.com/add-ons/switchee), which, as I understand it, keeps the tags in unmatched conditions from being processed at all by EE.

  • #4 / Sep 13, 2011 6:46am

    Could it be that you haven’t closed the {gallery} tag properly? Not closing properly has given me many strange EE moments… 😉

    woops. I just made a typo while writing down this problem. The code above isn’t exact copy of the real code, just a stripped down version to illustrate the problem.
    In the original code the gallery tag is closed..

  • #5 / Sep 13, 2011 6:56am

    Andrew Weaver

    206 posts

    Try replacing the {if:else} with 2 separate if statements, e.g.:

    {if segment_2 == ""}
    ...
    {/if}
    {if segment_2 != ""}
    ...
    {/if}

    The {if segment_2 == ""} would normally be parsed first, but I think because you are using an {if:else} it turns into and “advanced” conditional and gets parsed after your gallery code.

    There’s some explanation here:
    http://www.derekallard.com/blog/post/simple-vs-complex-conditionals-in-expressionengine-templates

  • #6 / Sep 13, 2011 8:55am

    using SwitchEE works. ( thanks aelvan )

    {if segment_2 == ""}
    ...
    {/if}
    {if segment_2 != ""}
    ...
    {/if}

    doesn’t work.
    which is strange because it should according to:
    http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html


    The guide specifically states that advanced conditional are being parsed last, implying that basic conditionals aren’t. ( which doesn’t make much sense by the way )


    Does anybody know what the reasoning behind this is ? Why are these conditionals being parsed last ?
    There must be a damn good reason for this strange behavior, right ? 😊

  • #7 / Sep 13, 2011 9:18am

    A little follow-up about why Andrew’s code ( 2 separate if statements ) didn’t work.

    if there’s a complex if inside a simple if, both will be processed as complex if statements.  If statements inherent the complex status of their children.

    ( source: http://www.derekallard.com/blog/post/simple-vs-complex-conditionals-in-expressionengine-templates )

    And that’s exactly the case with my code, I’m using a couple of “advanced” conditionals in my 2 seperate, basic if statements.. screwing up the parse order.


    The question still remains: what’s the logic behind this strange parse order ?

  • #8 / Sep 13, 2011 9:49am

    aelvan

    33 posts

    I’m not going to pretend to have any in-depth knowledge of the parsing order, or why EE is doing it this way. 😊 But, if you look at LOW’s “ExpressionEngine’s Parse Order”, stuff like module and plugin tags are parsed between “Simple” and “Advanced” conditionals.

    So, the way I understand it, having both of these enables us to make conditionals that are parsed both before and after stuff like modules and plugins. This is of course a nice feature, if the alternative was to only be able to do one thing. The simple conditionals only work if what you’re testing for is parsed earlier in the parse order, and it automatically turns into an advanced one if what you’re testing for is parsed later.

    They could of course have enabled us to do both by making both an {early:parsed:if} and a {late:parsed:if} tag-pair, but I guessed they did it the other way to make it easier for beginners or something.. “This is an if. That’s it. Nothing more to see here. Move along”. I think that’s an ok decision, given that EE targets both entry level coders and more advanced coders. 😊

    I think the simple solution to your problem would be the EE swiss army knife; Embeds. 😊

  • #9 / Sep 13, 2011 6:22pm

    Dan Decker

    7338 posts

    Hello Jan van Lysebettens,

    With the use of SwitchEE, are you all set? Is there anything else we can assist you with?

    Cheers,

  • #10 / Sep 22, 2011 9:24am

    Hello Jan van Lysebettens,

    With the use of SwitchEE, are you all set? Is there anything else we can assist you with?

    Cheers,

    I’m all set now, thanks 😊

  • #11 / Sep 22, 2011 7:42pm

    Dan Decker

    7338 posts

    Jan van Lysebettens,

    Excellent! If you need us in the future, feel free to start a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases