A comparison operator is a binary operator that takes two operands whose values are being compared. Comparison operators are used in conditional statements,  where the result of the comparison decide whether execution should proceed. They form the key to program flow control, known as conditional processing. The result returns a Boolean value.

List of operators

Operators Meaning Default syntax
== Equal operand == operand
eq operand eq operand
!= Not Equal operand != operand
neq operand neq operand
< Less number < number
lt number lt number
<= Less than or Equal to number <= number
lte number lte number
>= Greater than or equal to number >= number
gte number gte number
> Greater number > number
gt number gt number
Functional Syntax Operand operator ( Operand,Operand )
operand operator ( Operand operator Operand )
operand operator ( Operand operator ( Operand operator Operand ))

  • The two operands to be compared must be of the same type, either String or Boolean or Number.
  • The operation can be nested in another operation that accepts operand type of boolean.
  • The operands to be compared may be: An Blogger value, a data set, or the result of an Expression.
  • Equality and inequality operators can also compare Array with the same type of the operand.
  • When Operand type is String, it must be wrapped with DoubleQuote: "STRING".

Blogger Comparison Operator Example

Equal
<b:if cond='data:view.search.label == "foo"'>
  <!-- item -->
</b:if>
If the name of the label is foo. Block code inside the tags will be processed.
Not Equal
<b:if cond='data:view.type != "item"'>
  <!-- item -->
</b:if>
If the current page is not the type of "item" (is not an article or a static page), a code will be processed.
Less than or equal to
<b:includable id='post' var='post'>
    <b:if cond='data:post.numberOfComments lt 5'>
        <!-- item -->
    </b:if>
</b:includable>
The condition will meet if the number of comment in the posts is less than or equal to 5. We can use lte or <= symbol, but if we tent to use the symbol <= later on the symbol < will be parsed to "&lt;", this will also to avoid clashing brackets.
Nesting in Lamda
<b:with value='data:widgets.AdSense count (w => w.sectionId != "ads")' var='numMobileAds'>
  <!-- item -->
</b:with>
The output will be number of Mobile Ads.
With Logical Operator
<b:if cond='data:view.isMobile == "true" and data:view.isHomepage'>
  <!-- item -->
</b:if>
Item is displayed only in Homepage and if is Mobile view mode.
Functional Operation
<b:if cond='data:blog.isMobileRequest == "true" and (data:blog.pageType == "index" and data:blog.url != data:blog.homepageUrl)'>
  <!-- item -->
</b:if>
Item will only shown in Mobile Version only in the index page ( Search, Label ) but not on the Homepage.

Other operators

Share This

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