{ifset:condition:text:else_text}

Description

Prints text only when a condition has content. If condition is non-empty after trimming, ifset returns text; otherwise it returns else_text. Inside text or else_text the alias _#1 stands for the condition value, so you do not have to repeat the expression. A condition that is only an unresolved alias - a 10-character token like _#HEADLINE, or _#P followed by digits - counts as empty, so a missing or empty field falls through to else_text. ifset is variadic: you may chain several condition:text pairs and it returns the text of the first non-empty condition, with a trailing unpaired argument as the final else. Watch the colon delimiter - a colon inside text (a URL, a time, a CSS pseudo-class) starts a new argument and can break the expression. Only the chosen branch is expanded: commands in the texts that are not returned - a view, an include, a count - do not run at all, so they cost nothing. A branch that is itself a shortcut call (the underscore command), a dequote or an mlx_view command is expanded every time. In rare cases (conditions nested very deep, many computed options between the branches, or a parameter whose expansion could split it in two) AA falls back to expanding every parameter first.

Parameters

condition required

The value to test. If it has content after trimming, ifset returns text; otherwise it returns else_text. A condition that is only an unresolved alias (a 10-character token like _#HEADLINE, or _#P followed by digits) counts as empty. Usually a field getter such as {hl_href.........} or another expression. You may add more condition:text pairs after the first to chain alternatives.

text required

What to print when condition is non-empty. The alias _#1 inside text expands to the condition value, so you can reuse it without repeating the expression.

else_text optional

What to print when condition is empty (or an unresolved alias). Optional - if omitted, an empty condition yields an empty string. As the trailing unpaired argument it also serves as the final fallback when chaining several condition:text pairs.

Examples

test{ifset:hello:visible}
Expectedvisible
Actualvisible
The simplest form. When condition has content, text is printed; here the literal condition hello is non-empty so visible appears.
test{ifset::shown:hidden}
Expectedhidden
Actualhidden
When the condition is empty, ifset returns else_text instead. Here the condition is empty so the third argument hidden is printed.
test{ifset:Jane:Hello _#1}
ExpectedHello Jane
ActualHello Jane
Inside text the alias _#1 stands for the condition value, so you do not have to repeat it. With condition Jane the output is Hello Jane.
test{ifset:custom-url:_#1:/cz/clanky/default}
Expectedcustom-url
Actualcustom-url
The common value-or-default pattern: if the first argument has content, print it via _#1, otherwise use the else_text fallback. Here custom-url is set, so it wins. In real templates the condition is usually a field getter such as {hl_href.........}.
test{ifset:_#NOSUCH__:has value:no value}
Expectedno value
Actualno value
A condition that is only an unresolved alias - a 10-character token like _#HEADLINE, or _#P followed by digits - is treated as empty. So a missing or empty field falls through to else_text. Here _#NOSUCH__ does not resolve, so no value is printed.
test{ifset::skipped:found:matched:fallback}
Expectedmatched
Actualmatched
ifset is variadic: it tries each condition:text pair in order and returns the text of the first non-empty condition, with a trailing unpaired argument as the final else. Here the first condition is empty so it is skipped, the second condition found is non-empty, so its text matched is returned.
test{ifset:x:{define:ifsetbranch7:chosen}:{define:ifsetbranch7:other}}{var:ifsetbranch7}
Expectedchosen
Actualchosen
The define in the else text never runs, because only the returned text is expanded - so the variable keeps the value the chosen text gave it.