I recently made a change to the text/template and html/template packages which introduces a new block keyword and permits template redefinition. This provides a kind of template “inheritance” that one might expect coming from an environment like Django.
The docs for the block keyword:
{{block "name" pipeline}} T1 {{end}}
A block is shorthand for defining a template
{{define "name"}} T1 {{end}}
and then executing it in place
{{template "name" .}}
The typical use is to define a set of root templates that are
then customized by redefining the block templates within.
I’d be interested in hearing what people think of this, and whether it would work for them. If we’re going to make any changes to the design, we need to do it before 1.6.
I’ve been tracking the GitHub Issue on this and saw your CL push over the weekend.
I like the approach: it keeps with the fairly simple design of the */template packages and solves a pain point that a bunch of other template libraries have implemented on their own.
Further: I don’t see a ‘better’ way of implementing it. The doc example does a great job of demonstrating how to use the feature too.