extend and include templates
mostafasolati opened this issue · 1 comments
mostafasolati commented
How to extends a template from a layout or include a partial in our template ?
benbjohnson commented
@mostafasolati The .ego
files generate functions so you can call that function from within another template. If you need your template to wrap then you can include a closure as an argument.
For example, if you had a template.ego
file:
<%! func writeTemplateTo(w io.Writer, yield func()) error %>
HEADER
<% yield() %>
FOOTER
And you have your content page called mypage.ego
:
<%! func (tmpl *MyPage) WriteTo(w io.Writer) error %>
<% writeTemplateTo(w, func() { %>
CONTENT
<% } %>
Then you execute:
var buf bytes.Buffer
var tmpl MyPage
tmpl.WriteTo(&buf)
println(buf.String())
then you should see something like:
HEADER
CONTENT
FOOTER