Templates

A template is basically just a Golang .tmpl file containing some variables. These variables must be specified inside the gauguin.yaml file under the params key. These variables will be injected in your template at runtime.

Let's see an example template:

<!DOCTYPE html>
<html>
  <head>
    <link 
      href="https://fonts.googleapis.com/css2?family=Inter:wght@400;900&display=swap" 
      rel="stylesheet" 
    />
    <link 
      href="http://localhost:5321/public/templates/articles/opengraph.css"
      rel="stylesheet" 
    />
  </head>
  <body>
    <div 
      class="container" 
      style="background-image:url({{.image}})"
    >
      <h1>{{.title}}</h1>
      <p>{{.author}}</p>
    </div>
  </body>
</html>

If you're new to Golang, you may be wandering: "wtf is that {{.strange}} syntax?" well, this is a variable! Every query parameter will be mapped to a variable inside the template. Template can also contain some logic, but please refer to the official documentation for that.

Last updated