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.

Two Conditional Issues

January 06, 2012 9:32am

Subscribe [2]
  • #1 / Jan 06, 2012 9:32am

    Benjamin

    116 posts

    I ran in to 2 problems with conditionals, the first issue i’ve not yet solved, the second issue is solved but still would like a reasoning behind it so i can understand conditionals a little better.

    Problem 1:
    A not equal to comparison operator combined with OR doesn’t seem to work (the same works with the equal to “==” comparison operator).
    I’m trying the following code, but it doesn’t work, and I can’t find a reason why it shouldn’t work:

    {if segment_2 != "url-1" OR segment_2 != "url-2"}
    Do not show this content if segment_2 is either url-1 or url-2
    {/if}

    Taking it apart like this does work, but I prefer them combined to keep it simple:

    {if segment_2 != "url-1"}
    Do not show this content if segment_2 is url-1
    {/if}
    {if segment_2 != "url-2"}
    Do not show this content if segment_2 is url-2
    {/if}


    Problem 2:
    This one is ‘solved’ but i can’t understand why the first one doesn’t work, is that a parse order issue, there isn’t any info on this on the Conditional Global Variables Docs page.

    Why doesn’t this work:

    {if segment_3 == "{url_title}"} CONTENT {/if}

    But this does:

    {if "{url_title}" == segment_3} CONTENT {/if}
  • #2 / Jan 06, 2012 10:05am

    I’m unable to be of much use here, but, I’ve sometimes found that a pair of “quotes and curlies” is what’s needed for conditionals to execute properly.

    {if "{segment_2}" != "url-1" OR "{segment_2}" != "url-2"}
  • #3 / Jan 06, 2012 10:12am

    Benjamin

    116 posts

    Thanks Nick,
    Unfortunately I had already tried that, no luck either.

  • #4 / Jan 06, 2012 6:45pm

    Sean C. Smith

    3818 posts

    Hi Benjamin,

    Sometimes using conditionals can be tricky to get right. Re: your first question what you are using is considered an advanced conditional by EE and has implications for both parsing order and potentially speed. See this Excellent PDF by @low for more information on that.

    I think that if you change OR to XOR your conditional will then work - according to the docs:

    XOR - returns conditional’s contents if either condition is true but not both
    OR - returns conditional’s contents if either condition is true

    Regarding number 2 - I’m not sure about the answer, but I’ll ask one of our devs about this.

    Sean

  • #5 / Jan 07, 2012 5:14am

    Benjamin

    116 posts

    Thanks Sean,
    I had already tried XOR, no luck.

  • #6 / Jan 12, 2012 5:27pm

    Robin Sowell

    13255 posts

    Hrm- the first one is always going to be true.  (I swear- conditionals hurt my head sometimes!)


    if a != a or a != b - it will show
    if b != a or b != b - it will show
    if c != a or c != b - it will show

    Are you going for ‘Do not show this content if segment_2 is either url-1 or url-2’?  If so- try

    {if segment_3 != "a" && segment_3 != "b"}
    Do not show this content if segment_2 is either a or b
    {/if}

    Does that get what you’re shooting for?

     

  • #7 / Jan 12, 2012 5:45pm

    Benjamin

    116 posts

    Aahhh yes, at last! I had already given up and switched to a different approach, but your solutions works like i wanted it to work in the first place, and it’s cleaner then my work around!

    That said; my first thought seeing your approach is that it can’t possibly work because BOTH conditions have to be not true, and not just one, conditionals can really throw you off sometimes.

    Thanks!

  • #8 / Jan 12, 2012 8:59pm

    Robin Sowell

    13255 posts

    😉  Glad to help- I had to map it out before I was sure myself!

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

ExpressionEngine News!

#eecms, #events, #releases