This is the most used tag in Blogger Theming, together <b:if>, and a singleton <b:elseif/> and <b:else/> are a Conditional tag to give a statement which is used to perform different actions based on different conditions.

Syntaxes and Attribute

Blogger XML Language
<b:if cond='EXPRESSION'>
    <!-- executed if a specified condition is true -->
<b:elseif cond='EXPRESSION2'/>
    <!-- executed if upper condition test is false  -->
<b:else/>
    <!-- executed if all condition is false -->
</b:if>
These tag has only one attribute cond with the value either Boolean, String or Number or Blogger Expression.

Conditional Tags Example

With a Blogger data Expression
<b:if cond='data:view.isHomepage'>
    <!-- Execute -->
</b:if>
Execute only in Homepage.
With a Boolean data
<b:if cond='data:blog.pageTitle'>
    <b:if cond='false'>
        <!-- Execute -->
    </b:if>
</b:if>
When Blog has no page title, child span block will be executed.
With a comparison operator
<b:if cond='data:blog.isMobile == "true"'>
    <!-- Execute -->
</b:if>
Test statement if Blog view in Mobile mode, if true span block will be executed.
With a logical operator
<b:if cond='!data:view.isMobile and data:view.isHomepage or data:view.isSearch'>
    <!-- Execute -->
</b:if>
The current page view data:view will be test with cond data:view.isMobile with operator ! (not), if not mobile mode, it will check to next condition and. If both current page view is Homepage or Search page span block will be executed.
With a membership operator
<b:if cond='data:view.search.label in ["Foo", "Bar", "Baz"]'>
    <!-- span Block 1 -->
<b:elseif cond='data:view.search.label not in ["Baz", "Qux"]'/>
    <!-- span Block 2 --> 
<b:else/>
 
</b:if>
If current page view is label page, span Block 1 will be executed for label in Foo, Bar and Baz page, in the next statement it will look for Baz and Qux. Since statement only tell not in the label Baz and Qux, span Block 2 will also be executed for label Foo and Bar.
With a lambda operator
<b:if cond='data:posts any (p => p.labels any (l => l.name == "Foo"))'>
    <!-- Execute -->
</b:if>
The span block will be executed only if label match "Foo" in the post.


Other Tag

Share This

About
BloggerBasics101 is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
Misc
Course