Skip to content

text/template: make blocks easier to use #14285

Closed
@bep

Description

@bep

I spent a little too much time trying to get the new block syntax in Go 1.6 implemented in Hugo, with no success.

Which is telling me that you should try to supply a "more real" example in the documentation.

Hugo uses the built-in associative transitive map to store its templates, so adding a new template is something like:

hugoTemplates.New("homePage").Parse(someTemplate)

As I understand the new block implementation, one needs to first parse it with the master file (with the block keywords), then do a "overlay" (a modification, a re-parsing) of the same template with the template with the definitions.

How to do that with the above I cannot figure out (other than the simple standalone clone example in the doc -- I could clone it, but how do I replace the template in the map?).

My naive approach would be:

m, _ := hugoTemplates.New("home").Parse(master)
m.Parse(overlay)

And this works ... for the first template. Adding a second breaks in confusing ways.

Ref. gohugoio/hugo#1832

Also see #3812

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions