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 "<", 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.
Blogger , Tips and Tricks