Howdy everybody, I believe it’s higher to elucidate my query by way of code:
{{outline "base"}}
<h1>An instance template</h1>
{{block "sidebar" .}}
<p>My default sidebar content material</p>
{{finish}}
{{finish}}
<!-- child1.html -->
{{template "base" .}}
<!--
I need this web page's sidebar to point out:
<p>My default sidebar content material</p>
-->
<!--
Reply: simply do nothing
-->
<!-- child2.html -->
{{template "base" .}}
<!--
I need this web page to point out:
<p>My default sidebar content material</p>
<p>My customized sidebar content material</p>
-->
{{outline "sidebar"}}
<!-- Reply: ??? -->
{{finish}}
<!-- child3.html -->
{{template "base" .}}
<!--
I need this web page's sidebar to point out:
<p>My customized sidebar content material</p>
<p>My default sidebar content material</p>
-->
{{outline "sidebar"}}
<!-- Reply: ??? -->
{{finish}}
I’ve used this specific characteristic from Django[1] and Laravel[2], and am questioning methods to implement it with Go templates.
Thanks!
[1] How you can override templates | Django documentation | Django
[2] Blade Templates – Laravel – The PHP Framework For Internet Artisans
I used to be studying this thread earlier as properly – it did assist me perceive methods to accurately order my template parsing so overriding works correctly. Sadly I don’t assume it covers my specific query.
As I perceive it you need a base template and use templates for every web page inside the bottom template. I attempted to realize this, however I gave up. Now I’m utilizing “parts” at web page degree. Not unhealthy method, however not the best way I wished from the start. I’ve discovered this ok and simple to reuse parts as a substitute.