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

    General Usage

    If you know handlebars, you basically know how to use Velvet.

    Let's assume you have a template (a string of some kind):

    <!-- templates/index.html -->
    <h1>{{ name }}</h1>
      {{#each names}}
        <li>{{ @value }}</li>
    {{! "this is a comment and won't get printed" }}

    Given that string, you can render the template like such:

    func IndexHandler(c buffalo.Context) error {
      c.Set("names", []string{"John", "Paul", "George", "Ringo"})
      return c.Render(200, r.HTML("index.html"))

    Which would result in the following output:


    If Statements

    What to do? Should you render the content, or not? Using Velvet's built in if, else, and unless helpers let you figure it out for yourself.

    {{#if true }}
      render this

    Else Statements

    {{#if false }}
      won't render this
    {{ else }}
      render this

    Unless Statements

    {{#unless true }}
      won't render this