Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Switch and case

Choosing between several outputs with switch and case: matching a value, matching one of several values with in, the default case, why conditions belong in if, and when if or an override is the better tool.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/switch-case.md

On this page

Switch and case

This page is for designers who print one of several outputs depending on a value.

Contents

  1. Syntax
  2. Matching several values
  3. A condition
  4. When not to use it

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}
{/switch}

The 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' )}
    ...
{/case}

A 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}
    ...
{/if}

When 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}.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x