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.

bug with the {url_title} variable in an if/then statement

June 10, 2010 11:29am

Subscribe [4]
  • #1 / Jun 10, 2010 11:29am

    Discovered what I think is a bug with the {url_title} variable in an if/then statement. Perhaps there is something about the order of variables in if/then statements I am not aware of.

    The following doesn’t work:

    {if last_segment == "{url_title}"}true{/if}

    the following does:

    {if url_title == "{last_segment}"}true{/if}

    All that is different is the order of the variables.

    I tested all the following that did work:

    {if url_title == "{last_segment}"}true{/if}
    {if url_title == "{segment_2}"}true{/if}
    {if segment_2 == "{last_segment}"}true{/if}
    {if last_segment == "{segment_2}"}true{/if}
    {if last_segment == "bocce"}true{/if}
    {if url_title == "bocce"}true{/if}
    {if segment_2 == "bocce"}true{/if}

    I tested all the following that did NOT work:

    {if last_segment == "{url_title}"}true{/if}
    {if segment_2 == "{url_title}"}true{/if}

    Using EE 1.6.9. and Last Segment 1.0.2

  • #2 / Jun 23, 2010 6:57pm

    Lisa Wess

    20502 posts

    You should not quote and brace your conditionals.  Try this:

    {if segment_2 == url_title}
    {if url_title == segment_2}

    that keeps the plugin out of the question as well.

  • #3 / Jan 18, 2011 3:29pm

    cityzen

    83 posts

    I am having the same issue and can’t figure out what I’m doing:

    {if url_title == segment_3}do something{/if}

    This causes the white screen of death.  I do have matrix going and am trying this outside of the matrix loop.

    Any ideas?

    Upon further inspection, it seems like it is causing a conflict with Matrix.  I will see if I can track down a known bug for this in Matrix docs.

    Another update - I had segment_3 wrapped in curly braces in another conditional… my bad.  Resolved.

    EE 1.6.8

  • #4 / Jan 18, 2011 3:57pm

    Try

    {if url_title == '{segment_3}'}do something{/if}

    or

    {if '{url_title}' == '{segment_3}'}do something{/if}

    They say we don’t have to bracket and quote the variables in the conditionals but I do get different results from time to time.

  • #5 / Jan 18, 2011 3:59pm

    Lisa Wess

    20502 posts

    Hey guys,

    Quoting and bracing variables is not secure - especially with user input, such as segments.  See our FAQ on Troubleshooting Conditionals for an explanation.

  • #6 / Jan 18, 2011 4:02pm

    I hear you, but my experience tells me differently. And its not consistent either. So something is up but I am not a master coder so…

  • #7 / Jan 18, 2011 6:52pm

    Lisa Wess

    20502 posts

    Hi, Hendrik-Jan - if you choose to quote and brace your conditionals, just make sure you are aware of the security implications therein =)

  • #8 / Jun 04, 2011 11:27pm

    Sean C. Smith

    3818 posts

    You should not quote and brace your conditionals.  Try this:

    {if segment_2 == url_title}
    {if url_title == segment_2}

    that keeps the plugin out of the question as well.

    Lisa,
    I copied and pasted the above code (which I’d actually already tried) and it isn’t working for me. I’ve also tried several variations and nothing is working.

    currently I’ve got this code in a temporary spot which does not display, but if I remove the conditional it works fine

    {if segment_2 == url_title}{exp:channel:entries channel='blog' limit='1' disable='member_data|custom_fields|categories' status='open'}{title}{/exp:channel:entries}{/if}
    
    {if last_segment ==url_title}display something{/if}
  • #9 / Jun 06, 2011 11:23am

    Kevin Smith

    4784 posts

    Hey Sean–

    Since url_title is a channel entries single variable, those conditionals would have to go inside the channel entries tags. Is that where you have the second example placed?

    Kevin

  • #10 / Jun 06, 2011 6:50pm

    Sean C. Smith

    3818 posts

    Kevin,
    I ended up starting a new thread with specific details about this one, which you responded to a little while ago.

  • #11 / Jun 07, 2011 10:25am

    Kevin Smith

    4784 posts

    Oh man… I thought I was seeing double! Ok, I’ll close this one out and we’ll continue over there.

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

ExpressionEngine News!

#eecms, #events, #releases