Learn how to write Yumdocs templates with if tags.
Make sure you understand expressions before experimenting with if tags.
The examples below are live to allow you to experiment. Most limitations come from the fact that the web editor
input.docx has few capabilities compared to Microsoft Word. But note that you can download
improve layouts in Word and run
yumdocs input.docx data.json output.docx in a terminal window as explained
in our CLI Tutorial.
The if tag is a statement (or instruction) followed by a condition between delimiters
In Yumdocs, statements are prefixed with a hash
#, unless configured otherwise.
The condition is an expression which value is truthy or falsy
(for example, 1 is truthy and 0 is falsy. Also empty strings are falsy whereas non-empty strings are truthy).
#if tag is an opening tag, which requires a closing tag, i.e.
Yumdocs includes the content between the opening tag and the closing tag if the condition is met.
If the condition is not met, the content is discarded.
The if tag is also associated with an optional tag, i.e.
which allows for alternate content if the condition is not met.
Considering the condition
year3 > year2 is met in the following example,
We are doing great! is included and
We should improve! is discarded.