- Get link
- X
- Other Apps
b:switch
The b:switch tag, or the switch tag, is a tag for specifying the result for multiple possible values of a variable.
Attributes
var - Variable value on which to switch.
b:switch tags are combined with nested self-closing b:case and b:default tags.
b:switch tags are combined with nested self-closing b:case and b:default tags.
b:case
b:case tags are used within a b:switch tag to separate the output for each value case of the variable in the parent b:switch tag.
Attributes
value - Value which the variable has in order for this case to be rendered.
b:default
b:default tags define the default output when none of the other b:case values are the value of the variable in the parent b:switch tag.
Example usage
The following example emits a different greeting for each known language, defaulting to 'Hello world'.
<b:switch var='data:blog.locale.language'>
<b:case value='fr' />
<b:comment>French</b:comment>
Bonjour monde
<b:case value='it' />
<b:comment>Italian</b:comment>
Ciao mondo
<b:case value='de' />
<b:comment>German</b:comment>
Hallo Welt
<b:default />
<b:comment>Default - English</b:comment>
Hello world
</b:switch>
This would produce Bonjour monde on a French blog, Ciao mondo on an Italian blog, etc. Blogs which are not French, German or Italian would be treated as the default, which is English, Hello world.