Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend and include templates #27

Open
mostafasolati opened this issue Feb 10, 2017 · 1 comment
Open

extend and include templates #27

mostafasolati opened this issue Feb 10, 2017 · 1 comment

Comments

@mostafasolati
Copy link

How to extends a template from a layout or include a partial in our template ?

@benbjohnson
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants