liveBook · Manning

Multiple template arguments

As explained in Learn Go with Pocket-Sized Projects

Multiple template arguments are several logically distinct values combined into one data value so a template can access them during execution.

Go templates accept one value through Execute, so combine distinct values in a map when the template needs habits alongside date information. section 11.5.1

Pass habits and a formatted week

Execute the template with map[string]interface{}{"Habits": habits, "Date": week}. The template accesses these entries as .Habits and .Date, while methods such as .Date.Start and .Date.End provide formatted values.

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Implements map access, method calls, with scoping, and empty-list conditions without detailing template variable declarations.
Examples
Uses habits, a formatted week, date methods, a previous-week link, and an empty-list display condition.
What it assumes
Assumes Go and basic template execution; teaches map-backed data access and scoped template values.
What you can do after
Apply multiple values through Go template Execute and control their visibility with template actions.
How it connects
Connects Go templates with maps, methods, template actions, and conditional rendering.

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.