Monday, February 3, 2025

Blogger: How to Implement OR Operation Within b:if Block

AND

The AND condition can be implemented by stacking the b:if's.

For example:

<b:if cond='data:blog.pageType == "item"'>
    <b:if cond='data:blog.url != "post-URL-on-the-blog"'>
        [...custom content...]
        <b:elseif cond='data:blog.url == "another-post-URL-on-the-blog' />
        [...custom content -- inner b:if...]
        <b:else />
        [...custom content -- inner b:if...]
    </b:if>
    <b:else />
    [...custom content -- outer b:if...]
</b:if>

OR

The OR on the other hand, is done by actually placing OR operator, ||, within the b:if condition.

For example, we want to show custom content or executing script only on static page OR item (post):

<b:if cond='data:blog.pageType == "static_page" || data:blog.pageType == "item"'>
    [...custom content here...]
</b:if>

We can put more than two conditions for the OR.

condition-1 || condition-2 || condition-3 || ... || condition-N

That also applies to AND. We can stack them with more than two conditions.


More Reference

For more reference regarding b:if and b:else, please try this post:

Modern Zorro

No comments:

Post a Comment

Tell me what you think...