Skip to content

Instantly share code, notes, and snippets.

@low
Created November 24, 2011 16:49
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save low/1391783 to your computer and use it in GitHub Desktop.
Save low/1391783 to your computer and use it in GitHub Desktop.
Simple EE conditionals turning advanced -- an example
// This will execute the exp:tag if first segment is empty
{if segment_1 != ''}
{exp:class:method}
{if var == "foo"}
Lorem
{if:else}
Ipsum
{/if}
{/exp:class:method}
{/if}
// This will NOT execute the exp:tag if first segment is empty
{preload_replace:ifelse="{if:else}"}
{if segment_1 != ''}
{exp:class:method}
{if var == "foo"}
Lorem
{ifelse}
Ipsum
{/if}
{/exp:class:method}
{/if}
@low
Copy link
Author

low commented Nov 28, 2011

I've updated the gist to better demonstrate the principle I was trying to explain. No more 2 exp:tags, but a straight-forward advanced conditional inside an exp:tag for simple display purposes. The effect is the same.

@GDmac
Copy link

GDmac commented Jan 2, 2012

Lodewijk, after reading your blog and checking the template parse method (The tag is, as mentioned, instantly replaced, leaving no other tag with the same name in the template to be replaced by a second declaration). But also, because the tag is instantly replaced, this opens the door for variable-variables :-)

{preload_replace:foo="{bar}"}
{preload_replace:bar="interesting"}

{foo} // returns: interesting

@low
Copy link
Author

low commented Jan 2, 2012

Indeed. But be aware that the order in which you place the variables here is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment