Plugin

Developer
Supported

EE 1
EE 2
Switchee

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

     

You must be logged in to post.

Nested switchee, matrix and playa

Support Request

cbad
cbad

Hi Mark-

I’ve got a case where a nested switchee and all its tags are just getting output as text, rather than getting parsed. It’s a bit of a complicated scenario so that may be it.

Basically, I’m setting a stash variable for some content inside a matrix row which has a playa field in it. The nested switchee is inside the playa field. Here’s the code:

{stash:section-page-content}
 {sp
-items-matrix}
 {exp
:switchee variable="{pi-type}" parse="inward"}
  {case value
="topics"}
   {pi
-items-playa}

    
<div class="{switch='topic-row showleft|topic-row'}">
     
{switchee variable="{spt-media-type}" parse="inward"}
     {case value
="image"}
     
<h2>{spt-media-type}</h2>
     
{/case}
     {case value
="zoom"}
     
<h2>{spt-media-type}</h2>
     
{/case}
     {
/switchee}
    
</div> <!-- topic-row -->
  
   
{/pi-items-playa}
  {
/case}
 {
/exp:switchee}
 {
/sp-items-matrix}
 {
/stash:section-page-content} 

Here’s what the output for the switchee looks like (unstyled of course):

{switchee variable="zoom" parse="inward"} {case value="image"}
zoom
{
/case} {case value="zoom"}
zoom
{
/case} {/switchee} 

I can handle everything for this situation using {if}s, but If there is something wrong with my approach I’d like to know it. I have successfully used nested switchee statments in the past.

Thanks!

 

Mark Croxton
# 1
Developer
Mark Croxton

I expect it’s a parse order thing - the content inside the Playa tag pairs are not processed immediately, they get replaced with a standalone Playa tag with the same content inside. Could be that by that point the inner switchee tags are exposed in the document root. Difficult to say without a lot of testing.

You could always use if/else instead of the inner switchee and wrap with my ifelse plugin.

EDIT: are you using parse_tags=“yes” on the outer Stash tag with a depth > 1 ?