Golang template engine pipelines

There are 2 template packages, text/template and html/template. They have the same interface, but the html/template package is for generating HTML output safe against code injection, and should be used instead of text/template whenever the output is HTML. Since they have the same interface but the html/template provides some extra functionality (contextual escaping of the … Read more

Capture or assign golang template output to variable

There is no “builtin” action for getting the result of a template execution, but you may do it by registering a function which does that. You can register functions with the Template.Funcs() function, you may execute a named template with Template.ExecuteTemplate() and you may use a bytes.Buffer as the target (direct template execution result into … Read more

Go template name

The name of the template–unsurprisingly–is to name the template. What is it good for? As long as you don’t want to refer to the template, it doesn’t really matter. But if you want to refer to it, then yes, you refer to it by its name. When would you want to refer to it? When … Read more