2

I'm trying to use Switchee for this scenario:

{if variable_1}

    {if variable_2} some text {if:else} some other text {/if}

{if:else}
nothing to show!
{/if}

So, if i want to use Switchee i need to nest two plugins?

{exp:switchee variable="{variable_1}" parse="inward"}

    {case value="{variable_1}"}

        {exp:switchee2 variable="{variable_2}" parse="inward"}
            {case2 value="{variable_2}"}  some text {/case2}
            {case2 default="yes"} some other text {/case2}
        {/exp:switchee2}

    {/case}

    {case default="yes"}
     nothing to show
    {/case}

{/exp:switchee}

Help please! :) thank you

4

The nested instances of switchee should not have the exp prefix.

{exp:switchee variable="{variable_1}" parse="inward"}

    {case value="{variable_1}"}

        {switchee variable="{variable_2}" parse="inward"}
            {case value="{variable_2}"}  some text {/case}
            {case default="yes"} some other text {/case}
        {/switchee}

    {/case}

    {case default="yes"}
     nothing to show
    {/case}

{/exp:switchee}

Or you can test both variables at once:

{exp:switchee variable="{variable_1}/{variable_2}" parse="inward"}

    {case value="{variable_1}/{variable_2}"}
        some text
    {/case}

    {case value="{variable_1}/"}
        some other text
    {/case}

    {case}

    {case value="/"}
        nothing to show
    {/case}

{/exp:switchee}

You should know that variable_1 and variable_2 need to be parsed before switchee or this code will not work.

| improve this answer | |
  • 1
    note: you can use switchee inside a channel_entries tag on variables. So, var_1 and var_2 need only be early parsed if you use switchee outside of any other tags. – GDmac Apr 18 '14 at 10:32

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.