A template pipeline chains commands with |, passing each command’s output into the next command as its last argument. This keeps presentation formatting in the template while application logic supplies the underlying data. section 9.1.2
Use pipelines to:
- Format values, such as passing a time value through dateFormat with a layout string. section 9.1.2
- Combine built-in operations such as urlquery and html when constructing links or displaying content. section 9.1.1
- Iterate over slices with range and use nested conditional logic; inside range, . refers to the current item and $. accesses the outer scope. section 9.1.1
Formatting a date through a custom pipeline function
Register a Go function before parsing the template: funcMap := template.FuncMap{"dateFormat": dateFormat}; t := template.New("date").Funcs(funcMap); t = template.Must(t.Parse(tpl)). The template can then use {{.Date | dateFormat "Jan 2, 2006"}}. The function map exposes Go functions under template names, while the pipeline supplies .Date as the function’s final argument. section 9.1.2
{{"output" | printf "%q"}}
A minimal pipeline shows a literal flowing into printf and demonstrates the command-line-pipe analogy. section 9.1.2






























































