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("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 -->
<% } %>

Copyright © 2017 Buffalo. All rights reserved.

Buffalo Gopher designed by Ashley McNamara — Original Gopher designed by Renee French.