<p>Hello <a href="/r/golang" rel="nofollow">/r/golang</a>!</p>
<p>I am currently writing a web application and I was wondering if it is possible to achieve
template inheritance using the standard <code>html/template</code> package.</p>
<p>Basically, what I would like to do is to have a file called, let's say, <code>layout.html</code>, containing
the base layout of the page as well as some default values, and then many other
files like, for example, <code>index.html</code> or <code>list.html</code> that customize certain named blocks.</p>
<p>Basically, I would like to avoid stuff like:</p>
<pre><code>{{ include header }}
... content ...
{{ include footer }}
</code></pre>
<p>Any ideas ?</p>
<hr/>**评论:**<br/><br/>elithrar_: <pre><p><a href="https://tip.golang.org/pkg/text/template/#hdr-Actions" rel="nofollow">https://tip.golang.org/pkg/text/template/#hdr-Actions</a> - see the new <code>{{ block }}</code> action.</p></pre>znpy: <pre><p>It seems to be what I am looking for, but are there some examples somewhere ?</p></pre>znpy: <pre><p>For future reference: <a href="http://www.josephspurrier.com/how-to-use-template-blocks-in-go-1-6/" rel="nofollow">http://www.josephspurrier.com/how-to-use-template-blocks-in-go-1-6/</a></p></pre>rukittenme: <pre><p>This might help: <a href="https://www.reddit.com/r/golang/comments/27ls5a/including_htmltemplate_snippets_is_there_a_better/" rel="nofollow">https://www.reddit.com/r/golang/comments/27ls5a/including_htmltemplate_snippets_is_there_a_better/</a></p></pre>znpy: <pre><p>Thanks <a href="/u/rukittenme" rel="nofollow">/u/rukittenme</a> and <a href="/u/elithrar_" rel="nofollow">/u/elithrar_</a> , I will your links carefully and thoroughly as soon as possible!</p>
<p>In the meantime, upvotes for you :)</p></pre>