1

Sorry but I'm unable to use switchee.. how can i set AND conditionals?

this is my original code:

<!--The Categories Page ////////////-->
{if segment_2=="" AND segment_3==""}
{embed="travels/travels"}

<!--The Category Entries Page //////-->
{if:elseif segment_2!="" AND segment_3==""}
{embed="travels/trip"}

<!--The Single Entry ///////////////-->
{if:elseif segment_3!=""}
{embed="travels/trip"}

{/if}

thanks!

  • 2
    In this case it would be more useful using ifelse than switchee. Developed from the same author: Marc Croxton. – Stéphane Mar 2 '14 at 17:43
  • Yeah! ifelse works well in this case, thank you Stéphane – Valerio Mar 2 '14 at 18:44
2

It's easy, actually. You can concatenate both segments. I used to use some RegEx for this, but I just got the idea to take advantage of the parsing order.

Please, try this:

{exp:switchee variable="{segment_2}/{segment_3}" parse="inward"}
    {case value="/"}
        {embed="travels/travels"}
    {/case}
    {case value="{segment_2}/"}
        {embed="travels/trip"}
    {/case}
    {case value="{segment_2}/{segment_3}"}
        {embed="travels/trip"}
    {/case}
{/exp:switchee}

There's no performance gain by using switchee on this case because the embeds are parsed after the advanced conditionals.

| improve this answer | |
  • Thank you Robson, I'll try your solution and the if else add-on by Marc Croxton too.. I really need to boost the performance – Valerio Mar 2 '14 at 18:43

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.