Templating

Templating controls how a page is rendered. It uses variables, loops, conditions, and functions.

Params

Use to access a variable:

<title>{{ .Params.title }}</title>

Site

Use to access variables in config.toml:

<title>{{ .Site.title }}</title>

Conditions

{{ if isset .Params "title" }}
    <title>{{ .Params.title }}</title>
{{ else }}
    <title>{{ .Site.title }}</title>
{{ end }}

Variables

Set variables with $:

{{ $favorite_food := "Gazelle" }}
{{ $favorite_food }}

Looping

{{ $best_friends := slice "pumbaa" "timon" "nala" "rafiki" }}

<ul>
    {{ range $best_friends }}
        <li>{{ . }}</li>
    {{ end }}
</ul>

Footer Example

In config.toml:

[params]
name = 'Simba'

In `/layouts/partials/footer.html`:
{{ with .Params.hide_footer }}
<!-- No footer here! -->
{{ else }}
<footer>
Website made by {{ .Site.Params.name }} in {{ now.Year }}
</footer>
{{ end }}

Before <body> in /layouts/_default/baseof.html:

{{ partial "footer.html" . }}

In about.md, toggle the footer in the front matter:

hide_footer:true