{var:name:expression}

Description

Prints a named expression. With one parameter it prints a variable previously stored with define:name on the same page. With two parameters it both stores the second parameter under name AND prints it, so the value can be reused later by var:name. Variables live for the duration of a single page render only and are evaluated in source order, so the defining call must run before any var:name that reads it. Reading a name that was never defined prints nothing. The main use is to compute an expensive value once (a count, an aggregate, a lookup) and reuse it in several places, and to pass values between nested views. Note the parameterized form var:name:arg1:arg2 from older docs is not implemented; the second parameter is stored verbatim as the value, it is not a template argument.

Parameters

name required

The variable name. It is trimmed, so leading and trailing spaces are ignored. An empty name makes the whole expression print nothing. Use the same name in the matching define and var calls. Names are case sensitive.

expression optional

The value to store under name. Present it only to define and print in one step; this also stores the value so a later var:name can reuse it. It is NOT trimmed, so leading and trailing spaces are kept. It is stored verbatim as the value - it is not a parameterized template, the older arg1:arg2 syntax was never implemented. Omit this parameter to read a value already defined elsewhere on the page.

Examples

test{var:greeting:Hello}
ExpectedHello
ActualHello
The two-parameter form stores the value under the name AND prints it in one step. Here greeting is set to Hello and Hello is printed.
test{define:city:Praha}{var:city}
ExpectedPraha
ActualPraha
define stores a value; a later var with one parameter prints it. The define must come before the var on the page.
test{var:total:{count:a-b-c}} items, then {var:total}
Expected3 items, then 3
Actual3 items, then 3
The common pattern: compute an expensive value once with the two-parameter form, then reuse it with the one-parameter form. count runs only once here.
test[{var:missing}]
Expected[]
Actual[]
Reading a name that was never defined prints nothing. The brackets are literal text added to make the empty result visible.
test{var:account:67230011/0100}
Expected67230011/0100
Actual67230011/0100
A handy idiom: the two-parameter form acts as an inline default - it sets account to a literal value and prints it. Slashes and other punctuation are fine as long as the value contains no bare colon.
test{var:label:Stav#: OK}
ExpectedStav: OK
ActualStav: OK
A bare colon in the value would split the parameters and break the define. Escape a literal colon as hash-colon. Here the value Stav: OK is stored and printed correctly.