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

     

Multiple Switchee Nestings Causing Categories PHP Error?

Support Request

pinkimp
pinkimp

Hello,

First of all, I just wanted to commend your work on this plugin. It is the single most useful tool I use for building really dynamic sites with EE.

I am having an issue with deeply nested sections in Switchee, and I’m curious if I’m approaching this the wrong way.

Here is an example of the code:

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

 {case value
=""}
        
default root page (/live)
 
{/case}        

      
 {case 
default="Yes"}   
      {switchee variable
="{segment_2}" parse="inward"}
        
        
  {case value
="{segment_2_category_url_title}"}
          {switchee variable
="{segment_3}" parse="inward"}
                
          {
/switchee} 
  {
/case}
        
            
  {case value
="events"}     
         {switchee variable
="{segment_3}" parse="inward"}
                                        
                {case value
=""}  
                   
                {
/case}
                
             {case 
default="yes"}
     {if switchee_no_results}{redirect
="live"}{/if}
             {
/case}             
          
         {
/switchee}      
  {
/case}   
        
        
  {case value
="online"}     
          {switchee variable
="{segment_3}" parse="inward"}           
                         
              {case value
=""}  
                  live
/online
              {
/case}                            
                                       
              {case value
="games"}   
                  live
/online/games
              {
/case}                             
                            
              {case value
="{segment_3_category_url_title}"}
                {switchee variable
="{segment_4}" parse="inward"}
                      
                  {case value
=""}             
                      live
/online/category                            
                  {
/case}
                    
                  {case value
="#^P(\\d+)$#|''"}             
                      live
/online/category/item                             
                  {
/case}
              
                  {case 
default="yes"}
                      {if switchee_no_results}{redirect
="live"}{/if}
                  {
/case} 
                  
                {
/switchee}           
              {
/case}          
              
              {case 
default="yes"}
                  {if switchee_no_results}{redirect
="live"}{/if}
              {
/case}             
        
          {
/switchee}      
  {
/case}  


  {case 
default="yes"}
   {if switchee_no_results}{redirect
="live"}{/if}
  {
/case}  
        
        
      {
/switchee}
 {
/case}
    
{
/exp:switchee} 

Now overall this works well, but once we’re on the live/online/games pages, and the subsequent categories, the exp:channel:categories tag is throwing out two PHP warnings with the following:

Message: preg_replace(): Unknown modifier ‘\’

Message: Cannot modify header information - headers already sent

Everything functions and the categories are being listed, yet the PHP warnings persist.

Does anyone have any input on this, or perhaps a different approach I could take?

Mark Croxton
# 1
Developer
Mark Croxton

Do you really have two backslashes in front of the d+ ? There should only be one (Devot:ee adds an extra one erroneously).

pinkimp
# 2
pinkimp

Nope, just the one - it was picked from other posts in the support forum here.

Any ideas, Mark?

Mark Croxton
# 3
Developer
Mark Croxton

Sounds like a bug with channel categories, if that’s what’s throwing the error? You can verify what Switchee is doing by turning on template debug and adding debug=“yes” to your switchee tags.

pinkimp
# 4
pinkimp

I’ll have to debug further, since I’m not entirely sure what I’m looking for in the Switchee debug output.

Apart from that, would you say my approach is ‘OK’, or is there a more efficient way of doing this?

Thanks for your help so far, Mark.