liveBook · Manning

Text/template package

The Go text/template package generates text from templates containing data substitutions and control logic without HTML-specific contextual escaping.

How 2 Manning books explain it

Go in Practice, Second Edition

The Go text/template package generates text from templates containing data substitutions and control logic without HTML-specific contextual escaping.

How it is used
Generates plain-text email and repetitive Go source from templates and supplied data.
How deep it goes
Works through buffered email rendering and a type-specific queue generator, but does not examine template-engine internals.
Examples
Uses a templated email message and a queue template that substitutes package and type names.
What you can do after
Apply it via text/template to render email into a buffer or generate type-specific Go source files.

Read how Go in Practice, Second Edition explains text/template package →

Learn Go with Pocket-Sized Projects

A Go template is a text-processing specification whose actions are evaluated against supplied data to produce formatted output.

How it is used
Generates formatted text when mixing static content and dynamic values would make string assembly cumbersome.
How deep it goes
Works through parsing and execution, actions, fields, iteration, and a CSS handler; does not descend into package internals.
Examples
Uses a habits list and an embedded stylesheet whose background and foreground colors come from supplied data.
What you can do after
Apply it via text/template to parse a separate template file and execute it with data in an HTTP response.

Read how Learn Go with Pocket-Sized Projects explains text/template package →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.