Text/template blocks and redefinition

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.

There’s an example of its usage in the tip docs.

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.

Andrew

11 Likes

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.

1 Like

@elithrar I’m sorry if it’s a bit of-topic, but could you please give us the link to this Github issue?

This one (which Andrew’s CL closed): https://github.com/golang/go/issues/3812

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.