1

I'm working on an old EE site (v2.5.2) which for reasons I won't go into I cannot update to a newer version.

I am trying to set a Stash variable based on whether or not a condition evaluates to true. But, because of the way this version of EE handles conditionals the Stash variable is always being set regardless of the actual condition.

Simplified code snippet:

{exp:stash:set_value name="sample" value="no"}

-- loop starts here --
{if entry_id==''}
    {exp:stash:set_value name="sample" value="yes"}
    Other stuff here
{if:else}
    Other stuff here
{/if}
-- loop ends here --

No matter whether entry_id is empty or not, the Stash variable always shows as "yes".

I've tried using Switchee and If:else but have had absolutely no luck getting this apparently simple thing to work.

How can I get around this? It's driving me nuts.

Real code snippet (using Cartthrob's cart_items_info loop) and following information found at https://devot-ee.com/add-ons/support/switchee/viewthread/6566

{exp:stash:set parse_conditionals="true" parse_tags="yes" process="start"}
    {exp:cartthrob:cart_items_info}
        {exp:switchee variable="{item_options:sample}" parse="inward"}
            {case value="true"}
                {stash:sample}yes{/stash:sample}
            {/case}

            {case default="yes"}
                {!-- nothing going on here --}
            {/case}
        {/exp:switchee}
    {/exp:cartthrob:cart_items_info}
{/exp:stash:set}

{exp:stash:get name="sample"}

That loop will output the correct information based on the value of {item_options:sample}. But the Stash variable is ALWAYS set to "yes" no matter what.

3 Answers 3

0

Some ideas you might want to try:

Use exp:stash:parse to make it parse the value at the end of the template https://github.com/croxton/Stash/wiki/%7Bexp:stash:parse%7D

{exp:stash:parse process="end"}
{exp:stash:get name="sample"}
{/exp:stash:parse}

Use {embed="..." sample="{exp:stash:sample}"} this always gets parsed at the end.

Wrap {exp:stash:set} around those tags like this:

{exp:stash:set name="sample" parse_conditionals="true" parse_tags="yes" process="start" parse_depth="4"}
    {exp:cartthrob:cart_items_info}
        {exp:switchee variable="{item_options:sample}" parse="inward"}
            {case value="true"}
                yes
            {/case}

            {case default="yes"}
               no
            {/case}
        {/exp:switchee}
    {/exp:cartthrob:cart_items_info}
{/exp:stash:set}

{exp:stash:get name="sample"}
0

What about checking the variable on getting instead?

{exp:stash:set 
    name="sample" 
    parse_tags="yes" 
}{exp:cartthrob:cart_items_info}{item_options:sample}{/exp:cartthrob:cart_items_info}{/exp:stash:set}


{exp:stash:get name="sample"}

{!--or:--}
{if {exp:stash:not_empty name="sample"}}
    Do something
{/if}

{!--or possibly:--}
{if sample}
    Do something
{/if}
0

I've actually managed to get this working but I'm not sure why it now does.

    {exp:cartthrob:cart_items_info}
        {exp:switchee variable="{item_options:sample}" parse="inward"}
            {case value="true"}
                {exp:stash:set name="sample" output="no"}yes{/exp:stash:set}
            {/case}

            {case default="yes"}

            {/case}
        {/exp:switchee}
    {/exp:cartthrob:cart_items_info}

I'm sure this isn't the best way but I've lost so much time on this that I'm moving on to something else.

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.