It is currently Sun Jan 29, 2023 3:22 pm

Blogger Ternary Operator

Blogger Ternary Operator

Post: #1

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

Operator Terner "STRING"

<b:with value='data:blog.isPrivate ? "Private" : "Public"' var='statut'>
  <b:eval expr='"This blog is " + data:statut'/>
</b:with>

Operator Terner "NUMBER"

<b:with value='data:blog.isPrivate ? "0" : "1"' var='mynumber'>
  <b:eval expr='data:mynumber'/>
</b:with>

Operator Terner "ARRAY"

<b:loop index='i' values='data:view.isHomepage ? data:posts limit 5 : data:posts' var='post'>
<b:include data='post' name='postCommentsAndAd'/>
</b:loop>

Operator Biner "STRING"

<b:eval expr='data:blog.pageName ?: data:blog.title'/>

Login

|

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 239 on Mon Dec 26, 2022 4:40 am

Statistics

Total posts 4 • Total topics 3 • Total members 1 • Our newest member admin