Plugin

EE 1
EE 2
IfElse
Editor's Pick
Each month the devot:ee staff picks an add-on that's especially well thought out, well built, and useful. They're add-ons that we love and think you will too!

IfElse was chosen in May 2012.

Developer

Mark Croxton

3rd Party (Free)

Download v1.4

Compatibility

  • LG Addon Updater
  • Multi Site Manager
  • Stand Alone Entry Form

Requirements

  • jQuery for the Control Panel

Tags

Early parsing of If/Else advanced conditionals.

Advanced conditionals in the ‘global’ template scope (not within a tag) are generally parsed by the EE template parser near the end of the process. This unfortunately means that any tags within non-matching conditions are parsed first, before being removed. This can have a significant performance impact if the nested tags are doing a lot of processing, such as is the case with the {exp:channel} tag.

One way around this issue is to use embeds, which are parsed after advanced conditionals. Embeds however have their own overhead, as a new instance of the template parser is needed for each one.

Happily we can now force the early parsing of advanced conditionals. Only the matching condition will remain in the template to be parsed. Here are a few examples:

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

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} 
                No results 
            {/no_results}
        {/exp:channel:entries}
    {if:elseif segment_1 == 'news' AND segment_2 == ''}
         News landing page
    {if:else}
        News story page
    {/if}
{/exp:ifelse}

You can use any of the standard global variables, segment variables, member variables or embedded variables.

Nested tags
This plugin will not parse advanced conditionals *inside* any nested plugin/module tags; these will be left untouched for the parent tag to process.

IfElse cannot currently be nested inside itself due to a flaw in the way the EE template parser works. However, the if/else conditional tags themselves can be nested.

Download IfElse

EE Version Downloads Add-On Version Release Date
1.x Download 1.2.1 2010-10-14 12:00 AM
2.+ Download 1.4 2010-10-21 12:00 AM

IfElse Links

This entry was last updated May 1, 2012, 4:24 am.

Disclaimer: Information about ExpressionEngine add-ons is provided as a service to you, the user, and every member of the ExpressionEngine community. Devot:ee is not responsible if you hose, mangle, wreck, or otherwise destroy your EE website by installing an add-on that you found out about at this site, regardless of its rating, Favorites status, commercial or free status, or general popularity. Caveat EEmptor!

2 Reviews:

bjornbjorn 11.29.11

Rating - {addon_rating_average}

Perfect if you’re experiencing problems with EE’s performance! In many cases EE will run all tags inside all conditional brackets before stripping out what isn’t to be shown in the template. This happens even in cases where you think something is a simple conditional. Doesn’t happen with IfElse.

Martin Luff 02.14.11

Rating - {addon_rating_average}

I’ve found this to be super-useful; I can reduce the number of templates and do much more with more advanced conditionals without having to compromise performance. So far seems to work fine; full marks from me… ;)