Latest news, food, business, travel, sport, Tips and Tricks...

Blogger Ternary Operator

?: 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


<div expr:class='data:view.isMobile ? "responsive" : "desktop"'>

  <!-- item -->


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.


<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.