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.

Conditionals? Is it a bug?

March 28, 2012 2:56am

Subscribe [0]
  • #1 / Mar 28, 2012 2:56am

    Suraj Timalsina

    32 posts

    Hi,
    I have a simple conditional:

    {if segment_1 != ''}
        {if segment_2 == ''}
            Segment 1 is not blank and segment 2 is blank
        {/if}
    {/if}
    
    {if segment_1 != ''}
        {if segment_2 != ''}
            Segment 1 is not blank and so is the segment 2.
        {/if}
    {/if}

    Now, if I understood right, visiting site.com/segment1 should not process the second block of code. But, interesting enough, it processes the second block of code as well! What’s interesting though is, it does hide the content of second block code if only site.com/segment1 request made, which is expected and working properly on hiding the content but still processes the tags etc.

    Is it a known issue?

    EE tested on:
    v2.4.0 - Build: date 20120123

  • #2 / Mar 28, 2012 6:44am

    Suraj Timalsina

    32 posts

    So, this is how far I came up with…
    If there is a complex conditional WITHIN simple conditional, something unexpected happens!

    Example:

    {if segment_2 == ''}
        {if segment 1 != ''}
            Hi John Doe!
        {if:else}
            Sorry!
        {/if}
        {exp:channel:entries channel="blog"}
            {title}
        {/channel}
    {/if}

    So, in above code, the channel:entries still gets called even if the simple conditional is true! If I remove the complex conditional,  and and if simple conditional is true, channel:entries does not get called.

    Is there any way we could not have the channel:entries called within a simple conditional that also has complex conditional? This definitely seems a bug.

     

  • #3 / Mar 29, 2012 1:08pm

    Dan Decker

    7338 posts

    Hi Bishnu,

    Conditionals can be tricky! Essentially, having and advanced conditional nested in a simple conditional forces the entire block to become advanced. If you read ExpressionEngine’s Parse Order, you will note that module tags are parsed before advanced conditionals, so this is why the channel entries tags are ran regardless of the conditional. The only thing that would be subject to the condition would be the output of the tags, but each instance will be parsed.

    I hope that clarifies this a bit for you.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases