{if1:condition:text:else_text}

Description

A strict boolean test against the literal value 1. Returns the second parameter (text) when the first parameter (condition), after whitespace is trimmed, equals exactly the one-character string 1; otherwise returns the third parameter (else_text), which defaults to empty. This is not a general truthiness test - only an exact 1 counts as true. The values 0, empty text, true, 01 and 1.0 all take the else branch. The typical use is with a checkbox or boolean field, which prints 1 when set and nothing when unset, so the condition reads that field-getter. For an any-non-empty-text test use ifset; for a numeric comparison with operators use if; for value equality use ifeq.

Parameters

condition optional

The value tested. It is trimmed of leading and trailing whitespace, then compared for exact string equality to the one-character string 1. Anything other than 1 (including 0, empty, 01, 1.0 or true) takes the else branch. Typically a checkbox or boolean field-getter, which prints 1 when set and nothing when unset.

text optional

The text returned when the condition equals 1.

else_text optional

The text returned when the condition is not 1. Optional - defaults to empty, so a two-argument call prints nothing on the false branch.

Examples

test{if1:1:published:draft}
Expectedpublished
Actualpublished
When the condition is exactly 1, the second parameter is returned.
test{if1:0:published:draft}
Expecteddraft
Actualdraft
Any value other than 1 - here 0 - returns the third parameter.
test[{if1:0:visible}]
Expected[]
Actual[]
The else_text is optional. With only two arguments a non-matching condition prints nothing (brackets added to show the empty result).
test[{if1::yes:no}]
Expected[no]
Actual[no]
An empty condition is not 1, so the else branch is taken.
test{if1: 1 :yes:no}
Expectedyes
Actualyes
Surrounding whitespace in the condition is trimmed before the comparison, so a padded 1 still matches.
test{if1:01:yes:no}
Expectedno
Actualno
The test is exact string equality, not numeric. The string 01 is not equal to 1, so the else branch is taken. (Use the if command for numeric comparison.)
test{if1:1.0:yes:no}
Expectedno
Actualno
Likewise 1.0 is not the string 1 and takes the else branch.
virtual{if1:{item:5726c2c6b035d7aab450d1794e9e90d7:_#SOLD_OUT}:Sold out:Registration open}
Expected(Sold out when the checkbox is set, otherwise Registration open)
ActualRegistration open
The real-world pattern: read a checkbox field of an item. A checkbox prints 1 when ticked and nothing otherwise, so this prints Sold out when the box is set, Registration open when it is not.
test{if1:1:{if1:0:A:B}:C}
ExpectedB
ActualB
if1 expressions nest. The outer condition 1 selects its text, which is itself an if1 whose condition 0 returns B.