The head and tail strings in a macro block are only generated when necessary. If the block returns nothing then the head and tail strings do not appear, which can help to control the creation of new lines.
Example |
---|
The text and new lines in the head and tail of
each .foreach_item loop are only
printed if the collection is not empty. When this template is
applied to a class with attributes but no operations, the text
// Operations and the new lines
specified before and after the operations list will not be
printed:class "%Code%" { .foreach_item(Attributes, // Attributes\n,\n\n) %DataType% %Code% .if (%InitialValue%) = %InitialValue% .endif .next(\n) .foreach_item(Operations, // Operations\n,\n\n) %ReturnType% %Code%(...) .next(\n) <Source> }Result: class "C1" {// Attributes int a1 = 10 int a2 int a3 = 5 int a4 <Source> } Note: To print a blank space between the curly brace
and the string // Attributes,
you must enclose the head string in
double-quotes:
.foreach_item(Attributes," // Attributes\n",\n) |