Prev: Next: Up: poundctl template[Contents][Index]


10.5.1 Template syntax

The syntax of poundctl templates is modelled after and mostly conforming to the specifications of the golang template module9.

Templates are executed by applying them to a JSON object. Annotations in a template refer to attributes of the object to control execution and derive values to be displayed. Execution of the template walks the structure and sets the cursor, represented by a period (called dot), to the value at the current location in the object as execution proceeds.

The input text for a template is as ASCII text is arbitrary format.

Actions (data evaluations or control structures) are delimited by ‘{{’ and ‘}}’; all text outside actions is copied to the output verbatim.

To aid in formatting template source code, if ‘{{’ is followed immediately by a minus sign and white space, all trailing white space is trimmed from the immediately preceding text. Similarly, if ‘}}’ is preceded by white space and a minus sign, all leading white space is trimmed from the immediately following text. Notice that the presence of the whitespace in these trim markers is mandatory: ‘{{- 3}}’ trims the immediately preceding text and outputs ‘3’, while "‘{{-3}}’ parses as an action containing the number ‘-3’.


Footnotes

(9)

https://pkg.go.dev/text/template