As of December 1st, 2019 Buffalo, and all related packages, require Go Modules and the use of the
GOPATH
is no longer supported.
Please see this blog post for more information https://blog.gobuffalo.io/the-road-to-1-0-requiring-modules-5672c6b015e5.
Templating
This document only applies when using https://github.com/gobuffalo/buffalo/render.
Please see github.com/gobuffalo/plush for more details on the underlying templating package.
Buffalo defaults to using plush as its template engine.
General Usage
// templates/index.html
<h1><%= name %>
<ul>
<%= for (name) in names { %>
<li><%= name %>
<% } %>
</ul>
// actions/index.go
func IndexHandler(c buffalo.Context) error {
c.Set("name", "Mark")
c.Set("names", []string{"John", "Paul", "George", "Ringo"})
return c.Render(200, r.HTML("index.html"))
}
// output
<h1>Mark
<ul>
<li>John
<li>Paul
<li>George
<li>Ringo
</ul>
If Statements
<%= if (true) { %>
<!-- render this -->
<% } %>
Else Statements
<%= if (false) { %>
<!-- won't render this -->
<% } else { %>
<!-- render this -->
<% } %>
Feedback
If you found an error or something which needs to be improved, and you want to contribute to fix it:
If you'd like to suggest something to improve this page: