Latest news, food, business, travel, sport, Tips and Tricks...

Blogger b:if, b:else and b:elseif Tag

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

,
//