Hi there,
Why does this work:
{if url_title == '{segment_2}’}
But this doesn’t?
{if segment_2 == '{url_title}’}
Thanks in advance,
L.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
May 04, 2011 2:37pm
Subscribe [4]#1 / May 04, 2011 2:37pm
Hi there,
Why does this work:
{if url_title == '{segment_2}’}
But this doesn’t?
{if segment_2 == '{url_title}’}
Thanks in advance,
L.
#2 / May 04, 2011 3:22pm
in short i dunno… but i bet this would.
{if "{url_title}" == "{segment_2}"}
{if "{segment_2}" == "{url_title}"}#3 / May 04, 2011 4:22pm
Did you try:
{if url_title == segment_2}#4 / May 04, 2011 4:27pm
Thanks both,
I’m actually able to achieve what I want with this:
{if url_title == ‘{segment_2}’}My question is, why does that above work, when the one below does not?
{if segment_2 == ‘{url_title}’}#5 / May 04, 2011 4:32pm
Because putting quotes around variable names can cause the conditional to check against the literal value rather than the contents of the variable. I avoid it generally.
#6 / May 04, 2011 5:01pm
I’m not sure I follow this logic either?
This is why I call it Strange Logic.
Because this works (note the ‘{segment_2}’:
{if url_title == ‘{segment_2}’}But this doesn’t (note the ‘{url_title}’):
{if segment_2 == ‘{url_title}’}???
#7 / May 04, 2011 5:06pm
I’ve had inconsistent results as well - and just never took the time to investigate them once I found that dropping all quotes was more reliable..😉
IIRC there was even a security risk in quoting variables - if the contents of the variable might contain user-provided content.
#8 / May 04, 2011 5:10pm
OK, thanks Boyink!
L.
#9 / May 05, 2011 2:18am
Loquela,
It’s a parsing issue you run into I believe. A segment variable is parsed first and then a simple conditional
{if url_title == '{segment_2}'}Doing it this way makes sure you are using the pre-parsed segment variable. The same way this might work
{if "{segment_2}" == "{url_title}"}