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.

Usage of Conditionals - executed queries

January 08, 2009 12:19am

Subscribe [3]
  • #1 / Jan 08, 2009 12:19am

    Erdal Demirtas

    84 posts

    Hi,

    I have a template like this:
    (I enabled “Display SQL Queries” and “Display Template Debugging?” options to see what’s happening.)

    {if segment_4}
    TESTING SEGMENT 4
    {/if}
    
    {if segment_4 == "" && segment_3 != ""}
    TESTING SEGMENT 3
    {exp:weblog:entries weblog="myweblog" url_title="{segment_3}" status="open" disable="member_data|trackbacks|categories|category_fields|pagination" dynamic="off"}
    <div id="article">
    <h1>{title}</h1>
    {body}
    </div>
    {/exp:weblog:entries}
    {/if}

    If I have an url like this -> http://www.domain.com/seg1/seg2/seg3/seg4/

    I expect to see just “TESTING SEGMENT 4” and “exp:weblog:entries” tag in the second condition should not be executed.

    RESULT: I see only “TESTING SEGMENT 4” as expected but the tag in the second condition is being executed.

    What am I doing wrong?

    Are the conditionals only for displaying tag outputs?

    Or is it the parse order?

    What should I do so that only the contents of “TRUE” condition will be executed?

    Thanks

    p.s.
    Version: 1.6.6 - Build: 20081212

  • #2 / Jan 08, 2009 11:30am

    Tim Stackhouse

    62 posts

    Try this:

    {if segment_4}
    TESTING SEGMENT 4
    
    {if:elseif segment_3}
    TESTING SEGMENT 3
    {exp:weblog:entries weblog="myweblog" url_title="{segment_3}" status="open" disable="member_data|trackbacks|categories|category_fields|pagination" dynamic="off"}
    <div id="article">
    <h1>{title}</h1>
    {body}
    </div>
    {/exp:weblog:entries}
    {/if}
  • #3 / Jan 08, 2009 11:45am

    Erdal Demirtas

    84 posts

    Thank you, but it does not help, I’ve already tested it.

    Template Debugging says:
    ...Parsing Tags in Template

    and all the tags in a template will be processed.
    The conditionals have no effect.

    If this is really the behaviour, I can even stop using EE.
    I do not want to use tons of embeds which is not good for performance.

    I hope there is an answer to this.
    I habe been waiting since last night.

    Thank you again.

  • #4 / Jan 08, 2009 11:51am

    Sue Crocker

    26054 posts

    Erdal, what is the reasoning behind what you’re trying to do? It might be easier to figure out a solution if we knew what the end result is.

  • #5 / Jan 08, 2009 12:14pm

    Erdal Demirtas

    84 posts

    Hi Sue,

    what i am trying to do is not really complex. It is described above.
    I have some logic in my template depending on the segments:
    If there are 4 segments do this
    If there are 3 segments do that
    If there are 2 segments do ...
    and so on

    The first segment is the name of the weblog and template-group.
    The others are entries in that weblog.

    What I want to learn is the behaviour of the EE in this case:
    “All” the tags will be processed in a template whether they are in a “TRUE” condition or not.
    Is this correct?

    This is what i understand from the results of debugging.
    You can easily test this. The template is really not complicated.

    As an experienced programmer I need this for lots of use cases, not only for this one.
    I expect that only the tags in the condition which TRUE to be executed.
    Let’s say there are 4 conditions in a template which only one of them can be TRUE at a time.
    But if at each request all the tags of all conditions will be processed, you end up with lots of unnecessary queries.

    If this is the case I must think about the whole software architecture.

    I really want to understand the behaviour of EE in this case.

    Thanks

  • #6 / Jan 08, 2009 12:24pm

    Sue Crocker

    26054 posts

    The way that EE works normally is for the third segment to hold the url_title of an entry. The fourth segment isn’t usually used for additional entries.

    As an example, let’s use a t-shirt.

    http://example.com/index.php/tshirt/order/sunset-tshirt/xxl/long-sleeve

    tshirt is the first segment, the template group name
    order is the template, second segment.
    sunset-tshirt is the weblog entry.
    xxl is a modifier for the sunset-tshirt for the size, (segment_4)
    long-sleeve is another modifier for sunset-tshirt in segment_5.

    But what you’re asking for I’ll go find out.

  • #7 / Jan 08, 2009 12:32pm

    Erdal Demirtas

    84 posts

    Hi Sue,

    thank you for the answer.

    I know how EE normally works.
    Because of this I have “dynamic=“off” in my “exp:weblog:entries” tags.

    What I am asking is totally different.

  • #8 / Jan 08, 2009 12:38pm

    Sue Crocker

    26054 posts

    Give this a try:

    {if segment_4 == ""}
    {if segment_3 != ""}
    TESTING SEGMENT 3
    
    {exp:weblog:entries weblog="default_site" limit="7" dynamic="off"}
    <h3>{title}</h3>
    <p>{summary}<br />
    <hr><br />
    {body}<br />
    {/exp:weblog:entries}<br />
    {/if} <br />
    {/if}

  • #9 / Jan 08, 2009 1:18pm

    Erdal Demirtas

    84 posts

    Thanks it works!

    I think this sentence of the documentation is the explanation:
    NOTE: Advanced Conditionals are evaluated after all EE tags are parsed.

    {if segment_4 == ""}
    {if segment_3 != ""}
    TEST 3
    {/if}
    {/if}

    is not equal to

    {if segment_4 == "" && segment_3 != ""}
    TEST 3
    {/if}


    The second one has advance conditionals.

    I hope there are not lots of people using this falsely as I did.
    As I said before the output is always correct but lots of queries are being processed at the background.

    Thank you again.

  • #10 / Jan 08, 2009 1:43pm

    Pascal Kriete

    2589 posts

    Oh those evil parse order things 😉 . Looks like Sue got you squared away though.

    Please don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases