Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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}  
share|improve this answer
    
Perfect - Thanks Jamie! –  madebyhippo Jan 31 at 16:04

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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