Template inheritance ?

blov · · 489 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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&#39;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>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

489 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传