Conditional text
Applies to: All programs with data
Text fields in templates can allow for conditional processing of text based on whether a certain condition is true or false. This is perhaps best explained by way of example
Consider a sports photographer offering trader cards with the following fields; name, position and height. The template might look something like this:
When all fields contain data the trader card will correctly displayNow consider a situation where the player has not supplied his or her position and subsequently the position field is empty. This will result in the following
It would be preferable if the header "Position" did not appear under these circumstances. Conditional text support will determine if the Position field contains data and process the Position: @Position text string accordingly. This is achieved by modifying the text string as follows:
Upon encountering a { character, everything up to the upright bar | becomes a condition. If text results from the condition(i.e. the condition is true), everything after the upright bar |is used. If no text results from the condition (i.e. the condition is false) the text is ignored. This would result in the following output.
The blank line is also undesirable but we can incorporate the carriage return into the condition as follows:
This will result in the following
Since there is nothing in the Position field and the condition
is therefore false everything between the curly brackets is ignored
including the carriage return (enter).
Of course the conditional processing can be extended to all the
fields as height data may also not be available. For example.
Furthermore it is possible to optionally specify alternative text to use when the condition is false by simply adding another upright bar and the replacement text. In the example above we may prefer to have the word "Utility" appear if no Position data is available. In this case we modify our text string as follows.
Now if the @Position is false i.e. there is no data in the Position field the word Utility will be used. This results in:
Due to the use of the curly brackets, { } in this way if you need to use the curly brackets in your text string simply enter double {{
End of article