Sometimes you may want text to be included in a document only if certain conditions are satisfied. For example, you may want to display a disclaimer section only if the document is a draft (see the
document.draft setting), or use a particular stylesheet only if when you generate a PDF document.
To do so, you can use the
condition macro (aliased by
?), and a set of additional macros that can be used as conditional operators i.e.:
Consider the following code:
In this case, if
document.draft is set to
true, “This is a first draft of the Glyph Book” will be displayed; if not, “This is the official version of the Glyph Book” will be displayed instead.
condition macro takes up to three parameters:
- the condition to evaluate
- the text to include in the document only if the condition is satisfied.
- (Optional) the text to include in the document if the condition is not satisfied.
Note that all parameters can contain macros, of course, so you can write things like:
In this case, the
pagination.css stylesheet is included only when you're generating a PDF document using Prince XML.
condition macro in Glyph works in a similar way as conditionals in programming languages: if the conditional expression (supplied as first parameter) is satisfied then the second parameter is executed or displayed. But when is a conditional expression satisfied? Glyph is a simple mini-language to perform text manipulation, and has no types, it can only understand text, therefore:
- A conditional expression is satisfied if it evaluates to a non-empty string except “false”.
- A conditional expression is not satisfied if it evaluates to an empty string or the string “false”.