liveBook · Manning

Html/template package

The Go html/template package parses and executes HTML templates with data substitutions, control logic, and contextual escaping of HTML-sensitive content.

How 2 Manning books explain it

Go in Practice, Second Edition

The Go html/template package generates HTML safely from templates containing data substitutions and control logic.

How it is used
Generates maintainable HTML responses by combining reusable markup, control logic, and Go data.
How deep it goes
Works through field substitution, contextual escaping, iteration, and template composition, then sketches more complex reuse patterns.
Examples
Uses an HTTP page handler, a comments iterator, shared head markup, and a base layout with overridable blocks.
What you can do after
Build it from scratch with html/template to render data into HTTP pages and reuse markup across templates.

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

Learn Go with Pocket-Sized Projects

html/template is Go's standard-library package for parsing and executing HTML templates with contextual escaping of HTML-sensitive content.

How it is used
Renders an HTML habits page for a browser-facing HTTP server backed by a gRPC service.
How deep it goes
Works through parsing, execution, actions, embedded files and reusable templates; does not explain escaping internals.
Examples
Uses a habit-count page, an extracted habit list item, a directory of embedded templates and a contrasting CSS template.
What you can do after
Build it from scratch: parse and execute an embedded HTML page, then split repeated markup into a named template.

Read how Learn Go with Pocket-Sized Projects explains html/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.