0

I have the following code in a template:

segment is: {segment_3} <br /> 
category is: {category_url_title}<br />
{if {segment_3} == {category_url_title}}
submenu goes here
{/if}

It gives the following output for categories that do not match the URL:

segment is: evaporated-apples
category is: frozen-apples 
submenu goes here

If I compare to a string literal, e.g., {segment_3} == "bacon", the conditional returns false. Why does comparing two variables that contain different strings return true?

3
  • 1
    Try by using like {if "{segment_3}" == "{category_url_title}"} ###### {/if} May 20 '13 at 18:49
  • Thanks, that's exactly it. Would you mind adding it as an answer so I can mark it? Bonus: do you know why it would resolve as true when I did it without quotes?
    – Michael
    May 20 '13 at 18:56
  • Yes sure, I posted my answer also. May 20 '13 at 19:29
3

In your case, you were comparing 2 variables (string) without quotes so both variables will be considered as TRUE i.e {if TRUE == TRUE} #### {/if}. In the same way when you put a single variable tag in if condition like {if variable_name} #### {/if} OR {if {variable_name}} #### {/if}

Having the quotes (single or double), EE considers the variable/s tag value as single string value and get compared correctly like:

{if "{segment_3}" == "{category_url_title}"} ###### {/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.