I'm trying to use the following conditionals in exp:stash:parse to set some values based on the category_id. However, I just can't get it to work and it always just gold for channel_colour or 20 for channel_category_group:

{exp:stash:set_list name="landing-{segment_1}" parse_tags="yes" parse_conditionals="yes" parse_depth="3" save="yes" refresh="60" scope="site" replace="yes"}
        {exp:stash:parse process="inline" parse_depth="2"}
        {categories limit="1" show_group="5"}
            {if category_id == "60"}
                {exp:stash:set_value name="channel_short_name" value="things-to-do"}
                {exp:stash:set_value name="channel_url" value="things-to-do"}
                {exp:stash:set_value name="channel_category_group" value="2"}
                {exp:stash:set_value name="channel_colour" value="blue"}
            {if:elseif category_id == "62"}
                {exp:stash:set_value name="channel_short_name" value="food-drink"}
                {exp:stash:set_value name="channel_url" value="food-drink"}
                {exp:stash:set_value name="channel_category_group" value="3"}
                {exp:stash:set_value name="channel_colour" value="red"}
            {if:elseif category_id == "61"}
                {exp:stash:set_value name="channel_short_name" value="stay"}
                {exp:stash:set_value name="channel_url" value="stay"}
                {exp:stash:set_value name="channel_category_group" value="4"}
                {exp:stash:set_value name="channel_colour" value="yellow"}
            {if:elseif category_id == "63"}
                {exp:stash:set_value name="channel_short_name" value="study"}
                {exp:stash:set_value name="channel_url" value="study"}
                {exp:stash:set_value name="channel_category_group" value="20"}
                {exp:stash:set_value name="channel_colour" value="green"}
                {exp:stash:set_value name="channel_colour" value="gold"}

Wondered if someone can help figure out what's going on?


  • What version of EE are you running? And what's in your channel:entries tag? (are you fetching multiple entries or just a single one?). How are you getting the variables? Jul 27 '16 at 11:50

[Updated in light of your comment...]

The problem is that you're using pre EE2.9, where the conditional parsing was improved to avoid the advanced conditionals trap (full story here if you're not aware of it: http://derekallard.com/index.php/blog/post/simple-vs-complex-conditionals-in-expressionengine-templates)

Basically in "advanced" conditionals, all of the tags get processed first before the irrelevant sections are removed from the output.

If you can't upgrade EE you could try Croxton's IfElse plugin, or Switchee. However, upgrading would be best, as dealing with these kind of things in pre 2.9 is an exercise in frustration.

  • Hey @James Smith. I have updated the code above to show what I currently have with channel entries tag and set list. Essentially each page has a category assigned. Now these category names match other channel names.So I get the client to check a category so that they can indicate which Channel and colours are pulled through to this page. The coded channel_category_group relates to other category groups rather than the 5 above. I'm using EE v2.8.1 and Stash v2.5.3. Jul 27 '16 at 13:01

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.