Switch and case
This page is for designers who print one of several outputs depending on a value.
Contents
Syntax
From lib/eztemplate/classes/eztemplateswitchfunction.php:
switch match=$node.class_identifier
case match='article'
<span class="badge">'Article'|i18n( 'design/mytheme' )</span>
/case
case match='event'
<span class="badge">'Event'|i18n( 'design/mytheme' )</span>
/case
case
{* no match: the case without a match is the default *}
/case
/switchThe media design's title template uses a switch on the error type and number to name error pages.
Matching several values
case in=array( 'article', 'blog_post' )
...
/caseA condition
{case} compares values only (match or in). A process= parameter appears in the class's comment as a TODO and
is not implemented. For a range or any other condition, use {if}:
if gt( $children|count, 5 )
...
else
...
/ifWhen not to use it
- Per content class markup belongs in override templates, not in one big switch (Node templates by class).
- Two branches are clearer with
{if}.
Related pages
- If and conditions
- Override basics
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.