Expressionengine plugin: If/Else advanced conditional logic early parsing
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Version 2.0.1


Early parsing of advanced conditionals in EE templates.


  1. Create a folder called 'ifelse' (note: all lowercase) in ./system/expressionengine/third_party/
  2. Copy the file pi.ifelse.php into this folder


Use like this when you want to parse conditionals that wrap tags, BEFORE those tags are parsed. Only the tags inside matching conditionals will subsequently be parsed.

{exp:ifelse parse="inward"}	
	{if member_id == '1' OR group_id == '2'}
		Admin content
	{if:elseif logged_in}
		Member content
		Public content

Parsing global variables and Stash variables

{exp:ifelse parse="inward" parse_vars="yes"}	
	{if stash:my_var == "one"}
	{if:elseif my_snippet_var == "two"}

"Unsafe" conditional parsing

Use this method only when you want advanced conditionals to be parsed AFTER the tags IfElse wraps have been parsed. The safe="no" parameter disables certain checks and safety measures and can signigicantly reduce the overhead of EE's own advanced conditional parser (savings of up to 1/4 of total template execution time are possible). This works best when you have a large number of conditionals.

The protect="" parameter can be used to specify special types of content to protect while parsing connditionals when using the "unsafe" method (currently 'javascript' and 'php').

{exp:ifelse safe="no" protect="javascript|php"}	
	{if "{segment_1}" == "about"}
	{if:elseif "{segment_1}" == "services"}

Please be aware that when using safe="no" you may see parse errors with some conditionals that make use of un-quoted variables.

Avoid this syntax where possible:

{if my_variable == "about"}...{/if}

Do this instead:

{if "{my_variable}" == "about"}...{/if}

When evaluating variables containing numbers, it's safe to do this:

{if {my_number} == 2}...{/if}

Preserving {if no results}

To preserve {if no results} conditionals inside nested tags, wrap your 'no results' content with {no_results}{/no_results}. Example:

{exp:ifelse parse="inward"}	
	{if segment_1 == 'news' AND segment_2 == 'category'}
		News category page
		{exp:channel:entries channel="news"}
				No results 
	{if:elseif segment_1 == 'news' AND segment_2 == ''}
	 	News landing page
		News story page

Nested conditionals

With parse="inward" is used with this plugin, advanced conditionals inside any plugin/module tag pairs wrapped by IfElse will not be evaluated; these will be left untouched for the parent tag to process.