<p>Hi guys! </p>
<p>Someone knows how to use echo with nested templates?
I'm using echo for a side project, and I read their doc <a href="https://echo.labstack.com/guide/templates" rel="nofollow">https://echo.labstack.com/guide/templates</a>, but I never used golang templates before, and I don't know how can I change the method <code>render</code> to use a base layout and some nested templates.</p>
<p>Something like this:</p>
<pre><code>server.go
\views
- layout.tmpl
- about.tmpl
- index.tmpl
//layout.tmpl
{{ define "layout" }}
<html>
<head>
{{ block "title" . }}
</head>
<body>
{{ block "content" . }}
</body>
</html>
{{ end }}
//index.tmpl
{{ define "title" }}
<title>
my index title
</title>
{{ end }}
{{ define "content" }}
<h3>
my index content
</h3>
{{ end }}
//about.tmpl
{{ define "title" }}
<title>
my about title
</title>
{{ end }}
{{ define "content" }}
<h3>
my about content
</h3>
{{ end }}
</code></pre>
<p>Thanks!</p>
<hr/>**评论:**<br/><br/>Nazariglez: <pre><p>The answer! -> <a href="https://gist.github.com/rand99/808e6e9702c00ce64803d94abff65678" rel="nofollow">https://gist.github.com/rand99/808e6e9702c00ce64803d94abff65678</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传