{iftext:condition:text:else_text}

Description

Conditional text. Like ifset, but it first strips HTML comments from the condition before testing it, so a condition that contains only an HTML comment counts as empty. If the condition has any real text left (after removing comments and trimming) and is not an unresolved field alias, the text branch is printed; otherwise the else_text branch is printed. You may chain several condition:text pairs - the text of the first non-empty condition wins, with the final leftover argument as the else_text. The alias _#1 inside the chosen text is replaced by the condition that matched (empty in the else branch). Parameters are not trimmed when stored and the result is never cached (runtime-evaluated). Typical use: emit an HTML attribute or label only when a possibly comment-only field actually carries content.

Parameters

condition required

The text to test. HTML comments are stripped first, then it is trimmed. The condition is considered set when something non-empty remains and it is not an unresolved field alias such as _#HEADLINE. You may supply several condition:text pairs; the first condition that is set decides the output.

text optional

Printed when the condition is set. The alias _#1 inside it is replaced by the matching condition value.

else_text optional

Printed when no condition is set (the leftover trailing argument). Optional - if omitted, an unset condition yields an empty string.

Examples

test{iftext:Anna:Hello Anna:Hi there}
ExpectedHello Anna
ActualHello Anna
The condition Anna is non-empty, so the text branch is printed.
test{iftext::Hello Anna:Hi there}
ExpectedHi there
ActualHi there
An empty condition falls through to the else_text branch.
test[{iftext:<!-- internal note -->:visible:hidden}]
Expected[hidden]
Actual[hidden]
This is what sets iftext apart from ifset: a condition that contains only an HTML comment is stripped to empty, so the else_text branch is printed. The brackets show there is no stray output.
test{iftext:Live <!-- draft --> copy:show:skip}
Expectedshow
Actualshow
Comments are removed but the surrounding real text remains, so the condition is set and the text branch is printed.
test{iftext:Praha:Selected city is _#1:none}
ExpectedSelected city is Praha
ActualSelected city is Praha
Inside the chosen text, _#1 is replaced by the condition value that matched.
test{iftext::skipped:Bob:Hello Bob:nobody}
ExpectedHello Bob
ActualHello Bob
You can chain condition:text pairs. The first condition is empty (its text skipped is ignored), the second condition Bob is set, so its text Hello Bob wins. The trailing nobody is the else_text.
test[{iftext::only when set}]
Expected[]
Actual[]
With no else_text given, an unset condition produces an empty string.
test[{iftext:<!-- no alt yet -->: alt="_#1": alt="image"}]
Expected[ alt="image"]
Actual[ alt="image"]
A common real-world pattern: emit an attribute only when a field carries real content. Here the field holds only a comment, so iftext treats it as empty and falls back to the default attribute. Parameters are not trimmed, so the leading space before alt is preserved.