1

I have the following at the top of one of my pages:

{if "{fn_zone}"!=""}
    {redirect="/store"}
{if:else}

{exp:stash:destroy name="delivery_day"}

.... More stuff ....

{/if}

However, what I'm finding is that regardless of the conditional the stash variable is always being destroyed.

I've even tried changing it to the following:

{if "{fn_zone}"!=""}
    {redirect="/store"}
{/if}
{if "{fn_zone}"==""}
    {exp:stash:destroy name="delivery_day"}
{/if}

Yet its still doing the same.

Can anyone advice how to deal with this?

2 Answers 2

3

The quotes around {fn_zone} mean it's an advanced conditional which may be the problem.

Can you do:

{if fn_zone == ""}
...
{/if}

Or you may have to use the if:else plugin:

{exp:ifelse parse="inward"}  
    {if "{fn_zone}"!=""}
        {redirect="/store"}
    {if:else}

        {exp:stash:destroy name="delivery_day"}

    {/if}
{/exp:ifelse}  
0
2

Yes, that is because the conditional is an advanced one, and will be parsed after plugin tags (ie Stash) (ref LOW's parse order PDF).

If the conditional was a simple one, this could work, but that depends on what {fn_zone} is. Only segment, embed, global variables are parsed as simple, and you have to write the left hand part of the conditional witout curly braces and string identifiers. If {fn_zone} is a global variable, something like this could do the trick:

{if fn_zone!=""}
    {redirect="/store"}
{/if}
{if fn_zone==""}
    {exp:stash:destroy name="delivery_day"}
{/if}

But, my goto solution in these cases is to use Croxtons Switchee or IfElse plugins, and have parse="inward" enabled. With switchee it would be something like this:

{exp:switchee variable="{fn_zone}" parse="inward"}
    {case value=""}
        {exp:stash:destroy name="delivery_day"}
    {/case}
    {case default="yes"}
        {redirect="/store"}
    {/case}
{/exp:switchee}

Hope that helps.

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.