Skip to content

text/template: allow newlines within actions and pipelines #29770

@bep

Description

@bep

This issue resurfaced in gohugoio/hugo#5604 -- but has been mentioned enough times to have proven its value.

In Hugo we have many variadic template functions. One relevant example would be the dict func that accepts a list of key/value pairs.

A current example would look like this:

{{ dict "country" "Norway" "population" "5 millions" "language" "Norwegian" "languageCode" "nb" "weather" "freezing cold" "capitol" "Oslo" "largest_city" "Oslo" "currency"  "Norwegian krone" "dialing_code" "+47" }}

The above would obviously be easier to read if it could be written something like this:

{{ dict 
	"country" "Norway" 
	"population" "5 millions"
	"language" "Norwegian"
	"language_code" "nb"
	"weather" "freezing cold"
	"capitol" "Oslo"
	"largest_city" "Oslo"
	"currency"  "Norwegian krone"
	"dialing_code" "+47" 
}}

The above creates a parser error, and is a common problem when you try to use one of the "HTML beautifiers" out there on Go templates.

As a person who have spent some thousand hours inside Go templates I would say that this issue is really, really worth it. And if you don't come from that background, I think it helps to be reminded that many Go applications needs a user interface, and Go templates is a natural choice. No one questions the value of gofmt and pretty Go code, not sure why the UI code should be treated differently. I know @natefinch tinkered with a "Go template formatter" some time ago. A solution to this partucular issue would make that task more enjoyable, me thinks.

/cc @regisphilibert

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions