v5Tutorial Complete Blogger Tutorials

Blogger <b:switch> Tag

Use b:switch tag to insert multiple b:elseif like tags.
  • Don’t need to repeat the variable name.
  • Easily read variables to see what defines each case, and what the default case is.

HTML b:switch Syntax

Each Blogger Loop in your template has opening and closing tags.

<b:switch var='Data Expression'>
<b:case value="Value1" />
 Display if Value1 is equal
<b:case value="Value2" />
 Display if Value2 is equal
<b:default />
 Display if not equal to any other b:case
</b:switch>
b:case tag can be repeted as need.

Usage of b:switch Tag

Go to Template > Edit HTML.

Blogger Section: new

<html>
<head>
<title><data:blog.pageTitle/></title>
<b:skin/>
</head>

<body>
<b:switch var='data:blog.pageType'>
<b:case value="static_page" />
  <h1>Page</h1>
<b:case value="item" />
  <h1>Post</h1>
<b:default />
  <h1>Blog Posts</h1>
</b:switch>

<b:section id='new'>
  <b:widget id='Blog1' type='Blog'/>
</b:section>

</body>
</html>

Post

This example shows how to output a different text header, depending on what type of page is being rendered.

HTML b:switch Attributes

Attribute Values Description
var name Defines Data expression name.

HTML b:case Attributes

Attribute Values Description
value name Defines Data expression value.

Related Post

Java Scripts