Test conditions to produce text only when needed
Template create table $table$ ($for columns$ $column$ $type$ $if size$($size$)$end$ $unless _last$,$end$$end$);alter table $table$ add primary key (ID);
Notes:
We solve these problems using conditional directives. There are two kinds of conditional directive. The if directive only generates text in its block if the specified condition is true, and the unless directive only generates text if the condition is false.
In this example, $if size$ tests whether a size keyword exists in the dictionary of the current element. If so, the size, enclosed in parentheses, is inserted in the output. If not, that section of text is omitted.
Furthermore, $unless _last$ tests whether the special _last key exists, and if not generates a comma. The _last key is automatically and transparently associated with the last element of any list. There is also a _first key associated with the first element, and an _index key associated with every element. The value of _index is the element’s position in the list, starting with number 1. The _last and _first keys have no associated values.