?: or ternary condition is the only operator that takes three argument. Like the Selectors, the first is a comparison argument, the second is the result upon a true comparison, and the third is the result upon a false comparison. This operator is frequently used as a shortcut for the if / else statement. An expression Baz ? Foo : Bar will evaluates to Foo if the value of a is true, and otherwise to Bar.

[Baz ? Foo : Bar] In this operator, the first operand must be Boolean. The last two operands can be of any type. One of the two will be the final result of the operation depending on the result of the first operand.

Blogger Ternary Operator Syntax

boolean ? value if true : value if false

Blogger Ternary Operator Example

Select between two Class
<div expr:class='data:view.isMobile ? "responsive" : "desktop"'>
  <!-- item -->
</div>
This is example of choice between class given in <div> tag. If condition blog view is in mobile mode or has parameter m=1, the tag will get "responsive" class, otherwise "he will get "desktop" class.

Substitute Gadget Title Name
<h1><b:eval expr='data:title ? data:title : "isEmpty"'/></h1>
Code above is example of substitute gadget title like Label, HTML, etc. If the gadget has no title, the word "isEmpty will be there as the gadget title.


Other operators

Share This

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