Plugin

Archived
Forum
(read-only)

Switchee

ExpressionEngine 1.x, ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Switchee with segment_3

Support Request

Jon Livingston
Jon Livingston

In one template I would like to show a page with a list of communities, then another page that shows details about a specific community, then a third page that shows details about a specific neighborhood in that community.

Currently I have the first two working but I’m not sure how to view segment_3. Here’s my code for the first two:

{exp:switchee variable="{segment_2}" parse="inward"}
{case value
="#^P(\\d+)$#|''"
This shows the various communities
{
/case}

{case 
default="Yes"}
This shows a specific community
{
/case}

{
/exp:switchee} 

Any help would be appreciated.

springworks
# 1
springworks

You can nest switchee statements to test different URL segments, but you need to remove exp: from the nested switchee statements, see the examples on the Switchee Github page.

So your code could work like this:

{exp:switchee variable="{segment_2}" parse="inward"}
    {case value
="#^P(\\\\d+)$#|''"
    This shows the various communities
    {
/case}

    {case 
default="Yes"}

        {switchee variable
="{segment_3}" parse="inward"}

            {case value
="#^P(\\\\d+)$#|''"
            This shows the neighbourhoods in a specific community
            {
/case}

            {case 
default="Yes"
            This shows a specific neighbourhood
            {
/case}

        {
/switchee}

    {
/case}

{
/exp:switchee} 

You can continue nesting Switchee like this to switch depending on the value of all the URL segments you are using.

MobsterEE
# 2
MobsterEE