October 2015
Beginner to intermediate
400 pages
14h 44m
English
The previous example does only the simplest possible formatting,
for which Printf is entirely adequate. But sometimes
formatting must be more elaborate, and it’s desirable to separate
the format from the code more completely.
This can be done with the text/template and
html/template packages, which provide a mechanism for
substituting the values of variables into a
text or HTML template.
A template is a string or file containing one or more portions enclosed
in double braces, {{...}}, called actions. Most of the string is printed literally, but the actions trigger other behaviors. Each action contains an expression in the template language, a simple but powerful notation for printing values, selecting struct fields, ...