1

I asked this also on Devotee - apologies for posting in both places but I guess here is better.

I’m setting several variables in the Channel Entries loop like so:

{exp:stash:set name="var1" parse_tags="yes"}{custom_field}{/exp:stash:set}

Then outputting them later outside the channel like this:

{exp:stash:get name="var1" default="uff" process="end"}

Which works fine. But then I want to compare “var1” to Segment_3 but can’t find any syntax/conditional which will work…either it outputs nothing or both conditions are true - have tried with If/else plugin too.

I’m guessing it’s parse order? What’s the way to compare these values? I tried with this conditional:

{if segment_3 == "{exp:stash:get name='var1'}"}Success!{/if}

And it returns nothing when the condition is actually true and the ‘success’ when it’s false. Which is odd. Anyone shed any light?

1 Answer 1

0

It's a parse order issue: the conditional is being run before the stash variable is set. There may be a more efficient approach, but you can use stash parse to make it parse later:

{exp:stash:parse process="end"}
    {if "{segment_3}" == "{exp:stash:get name='var1'}"}Success!{/if}
{/exp:stash:parse}

(note the change to segment variable)

Or if you can use a snippet, try:

{exp:stash:set name="sn_var1" type="snippet"}{custom_field}{/exp:stash:set}

and retrieving:

{if sn_var1 == segment_3}success{/if}
1
  • This first one worked for me Romans...thanks!
    – segovius
    Feb 26, 2014 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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