logo Buffalo slack logo
Templating
Frontend

Templating

Buffalo defaults to using plush as its template engine.

General Usage

// templates/index.html
<h1><%= name %></h1>
<ul>
  <%= for (name) in names { %>
    <li><%= name %></li>
  <% } %>
</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</h1>
<ul>
  <li>John</li>
  <li>Paul</li>
  <li>George</li>
  <li>Ringo</li>
</ul>

If Statements

<%= if (true) { %>
  <!-- render this -->
<% } %>

Else Statements

<%= if (false) { %>
  <!-- won't render this -->
<% } else { %>
  <!-- render this -->
<% } %>