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

     

Help embedding categories into Switchee value field

Support Request

porpoise
porpoise

I’m trying to embed categories into a Switchee value field but can’t get it to work. I’m concerned it might be a bug. Can you help?

To head off parse order problems, I call the Switchee embed from my site/index template:

{embed="site/.cases" categories="{exp:channel:categories category_group="1" style="linear" backspace=“1”}{category_url_title}|{/exp:channel:categories}"

And this is the site/.cases template:

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

    {case value
="{embed:categories}"}
        {embed
="site/page" channel="page"}
    {
/case}

    {case 
default="yes"}
        {embed
="site/404"}
    {
/case}

{
/exp:switchee} 

It fails by going to the default case.

I tried embedding via Low Variables and Template Morsels both directly and through a similar embed method as above and they failed, too.

For example, if I embed a Low Variable into the case value like this…

{case value="{lv-categories}"}
  {embed
="site/page" channel="page"}
{
/case} 

...and then define the Low Variable as my categories…

about|sample-category|support|visit 

...it works.

But if, in my Low Variable I replace it with what will generate the same thing… 

{exp:channel:categories category_group="1" style="linear" backspace="1"}{category_url_title}|{/exp:channel:categories} 

...it fails.

I’m at my wits end! Any tips?

Mark Croxton
# 1
Developer
Mark Croxton

This isn’t to do with Switchee, you need to use single quotes inside the parameter quotes or EE gets confused:

{embed="site/.cases" categories="{exp:channel:categories category_group='1' style='linear' backspace='1'}{category_url_title}|{/exp:channel:categories}"

 

 

porpoise
# 2
porpoise

Bingo! Mark, you solved the problem. I updated this post to a “Support Request” rather than a “Bug Report” and appreciate the response.