4.6 Text and HTML Templates
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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access