📚 Looking for current Exponential documentation? This site contains legacy SDK & API reference docs (eZ Publish era). For up-to-date 2026 product documentation, visit doc.exponential.earth.

  eztemplate / function_switch  

<< Section   

Switch

The switch function allows conditional control of output. For instance you can display a piece of HTML code depending on a template variable. The matching can be directly between to types or matching for an element in an array.

The matching is done by creating one ore more case blocks inside the switch block. There must always be one default case present, a default case is created by inserting a case block without any parameters.

The parameter to a case can either be match which determines the value to match against, or in which must contain an array. The match does a direct match, while the in looks for a match among the elements in the array. The in parameter behaves differently if the key parameter is used, which must be an identifier, it then assumes that the array sent to in has an array for each element and uses the key to match a key in the sub array.

{let var=1}

{* regular match *}
{switch name=Sw1 match=$var}
  {case match=1}
  This one matches.
  {/case}

  {case match=2}
  This one does not match.
  {/case}

  {case}
  Not this one either.
  {/case}
{/switch}

{* in array matching *}
{switch name=Sw2 match=$var}
  {case in=array(1,2)}
  This one matches.
  {/case}

  {case in=array(2,3)}
  This one does not match.
  {/case}

  {case}
  Not this one either.
  {/case}
{/switch}

{/let}

Exponential Copyright © 1998 - 2026 7x