Skip to content

Instantly share code, notes, and snippets.

@jonathaningram
Created February 10, 2014 02:06
Show Gist options
  • Save jonathaningram/8909167 to your computer and use it in GitHub Desktop.
Save jonathaningram/8909167 to your computer and use it in GitHub Desktop.
Illustrates the Golang error "template: redefinition of template %q"
{{ define "layout" }}
<html>
<body>
{{ template "navbar" . }}
<div class="content">
{{ template "content" . }}
</div>
</body>
</html>
{{ end }}
{{ define "navbar" }}
<div class="navbar1">
this is navbar 1, the default for the site
</div>
{{ end }}
{{ template "layout" . }}
{{ /* this is illegal because "navbar" is already defined */ }}
{{ define "navbar" }}
<div class="navbar2">
this is navbar 2, only for this special page - maybe it's a slimmed down version, or has different links
</div>
{{ end }}
{{ define "content" }}
the content for special page
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment