user2930576
user2930576

Reputation:

Blogger: Implementing a simple IF with an OR in the condition

In my blogger template I have the following code:

<b:if cond='data:blog.pageType == &quot;index&quot;'>
    <!-- A lot of lines of code -->
</b:if>

<b:if cond='data:blog.pageType == &quot;archive&quot;'>
    <!-- The same lines of code -->
</b:if>

It is possible to merge both 'if's in a unique expresión?. Something like using a simple logical OR?. I've tried the following with no result:

<b:if cond='data:blog.pageType == &quot;index&quot; ||
            data:blog.pageType == &quot;index&quot;'>

<b:if cond='data:blog.pageType == &quot;index&quot; &#124;&#124;
            data:blog.pageType == &quot;index&quot;'>

<b:if cond='data:blog.pageType == &quot;index&quot; OR
            data:blog.pageType == &quot;index&quot;'>

<b:if cond='data:blog.pageType == &quot;index&quot; || &quot;index&quot;'>

<b:if cond='data:blog.pageType == &quot;index&quot; &#124;&#124; &quot;index&quot;'>

Note: &#124; is the HTML expression for '|'.

I google it with no result, and I also reviewed blogger b:if statement, but I found no answer to this simple question.

----- edited -----

The desired result is having a code like:

<b:if cond='data:blog.pageType == &quot;index&quot;' || 
      cond='data:blog.pageType == &quot;archive&quot;'>
    <!-- A lot of lines of code -->
</b:if>

In this way, I don't repeat the block 'lot of lines of code', resulting a more maintainable code, and simplier.

Anyway, knowing how to do a simple OR is a good thing to furure cases.

Upvotes: 1

Views: 2067

Answers (2)

user2930576
user2930576

Reputation:

The only way I found to accomplish this is transforming the OR to nested, negated ANDs.

In this case, 'data:blog.pageType' has only 4 valid values: item, static, index and archive. So, the following code do the trick:

<b:if cond='data:blog.pageType != &quot;item&quot;'>
    <b:if cond='data:blog.pageType != &quot;static&quot;'>

        <!-- This block is run only when the pageType is archive or index -->
        <!-- A lot of lines of code -->

    </b:if>
</b:if>

Edit: This works fine, but maybe you'll want to try the accepted answer given by Marcos.

Upvotes: 1

Marcos
Marcos

Reputation: 3323

To simulate an OR operator in a blogger template, just use the IN operator.

In your case:

<b:if cond='data:blog.pageType in {&quot;index&quot;,&quot;archive&quot;}'>
    <!-- This block is run only when the pageType is index or archive-->
</b:if>

Upvotes: 4

Related Questions