<b:switch> tag, is a type of conditional statement that will evaluate an expression against multiple possible cases and execute one or more blocks of code based on matching cases. It includes <b:case/> and <b:default/> statement.

The Switches Blogger Syntax

Blogger XML Language
<b:switch var='EXPRESSION'>
    <b:case value='EXPRESSION1'/>
        <!-- execute case match VALUE1 code block -->
    <b:case value='EXPRESSION2'/>
        <!-- execute case match  VALUE2 code block -->
        <!-- execute case default code block if all case doesn't meet. -->
  • Tags <b:switch> can be nest.
  • Tags <b:switch> and <b:case> must have attribute.
  • Both <b:switch> and <b:case> value is either Boolean, Number, or String or 'data:' blogger expression.
  • The tags <b:case> and <b:default> must be nested in a tag <b:switch>.
  • The <b:case> tags are required and the tag <b:default> is not necessary.
  • The tag <b:case> can be used multiple times in a tag <b:switch>.
  • The tag <b:default> can only be used once in a tag <b:switch>.  
  • The tag <b:default> should be the last tag to be mentioned in the switch.

Switches tag Example

With String
    <b:loop values='["Fruit","Food","Other"]' var='MyList'>
        <b:switch var='data:MyList'>
            <b:case value='Fruit'/>
                <b:loop values='["Apple","Mango","Orange"]' var='Fruit'>
                    <b:switch var='data:Fruit'>
                        <b:case value='Apple'/>
                            <b:loop values='["Gala","Fuji"]' var='Kind'>
            <b:case value='Food'/>
            <b:loop values='["Meat","Vegetable"]' var='Food'>
            <b:loop values='["Milk","Seafood","Juice","Banana"]' var='Unlisted'>
HTML Rendered Result
  • Fruit
    • Apple
      • Gala
      • Fuji
    • Mango
    • Orange
  • Food
    • Meat
    • Vegetable
  • Other
    • Milk
    • Seafood
    • Juice
    • Banana

In the example, we have three data in the loop, its ready to print the output. But, before that, he found a Switch and have different case for every data we have earlier. The case is processing main data and adds another data to the main. The process repeat until all Switch and Case fulfilled, so, now our data will look like rendered result above.

Other Tag

Share This

Creative Commons License
Blogger Book is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.