logo Buffalo slack logo
Layouts
Frontend

Layouts#

This document only applies when using https://github.com/gobuffalo/buffalo/tree/main/render. Please see github.com/gobuffalo/plush for more details on the underlying templating package.

Using a Standard Layout#

It is quite common to want to use the same layout across most, if not all of an application. When creating a new render.Engine the HTMLLayout property can be set to a file that will automatically be used by the render.HTML function.

actions/render.go
templates/application.plush.html
templates/hello.plush.html
actions/hello.go
Output
var r *render.Engine

func init() {
  r = render.New(render.Options{
    // ...
    HTMLLayout: "application.plush.html",
    // ...
  })
}

Using a Custom Layout#

Sometimes, on certain requests, a different layout is needed. This alternate layout can be passed in as the second parameter to render.HTML.

Custom layouts do NOT work with render.Auto.
actions/render.go
templates/custom.plush.html
templates/hello.plush.html
actions/hello.go
Output
var r *render.Engine

func init() {
  r = render.New(render.Options{
    // ...
    HTMLLayout: "application.plush.html", // You can realize that render continues using the application.plush.html
    // ...
  })
}