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

     

Replacing segment if statement - getting stuck!

General

Richard Wiggins
Richard Wiggins

Hi Mark,

I’ve been recommended to use your plugin to try and speed up some of my templates, but I can’t get my head around trying to achieve the following if statement based around segments. Not sure if the following is actually achievable using Switchee?:

{if segment_3!=""}
 {exp
:channel:entries channel="products" limit="1" url_title="{segment_3}"}
  {embed
="_includes/header-meta-scripts" entry_id="{entry_id}"}
 {
/exp:channel:entries}
{if
:elseif segment_2!="" AND segment_3==""}
 {embed
="_includes/header-meta-scripts" title="{segment_2_category_name}"}
{if
:else}
 {embed
="_includes/header-meta-scripts" title="Default Product Title"}
{
/if} 

Cheers, Richard.

Mark Croxton
# 1
Developer
Mark Croxton

It’s doable in Switchee, but the quickest option with same benefit would be to wrap the whole block of code with my ifelse plugin instead.

{exp:ifelse parse="inward"}
your code block here
{
/exp:ifelse} 

switchee (note devot-ee is adding a backslash in front of every backslash!)

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

 {case value
="#^.*/\\S$#"}
  
...
 
{/case}
 
 {case value
="#^\\S/\\S$#"}
  
...
 
{/case}
 
 {case 
default="yes"}
   
...
 
{/case}
 
{
/exp:switchee} 

 

Richard Wiggins
# 2
Richard Wiggins

Thanks for getting back to me so quickly Mark. I’m now using your ifelse plugin instead.

Cheers!