Text/template package
The Go text/template package generates text from templates containing data substitutions and control logic without HTML-specific contextual escaping.
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
- html/template packagealternative to · The Go html/template package parses and executes HTML templates with data substitutions, control logic, and contextual escaping of HTML-sensitive content.
- ExecuteTemplateused by · ExecuteTemplate is a Go template method that renders a named template using supplied data.
- attributeuses · An attribute is a named property, value, or piece of information associated with an entity, object, or program element.
- template dotuses · The template dot is the Go template data-context expression representing the current value available to template actions.
- custom template functionuses · A custom template function is an application-defined function registered with a template engine and callable from template actions.
- slicinguses · Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
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.

