Skip to content

Layout

  • layouts/
  • HTML files to be used as templates
  • HTML files can use interpolation using Go
  • Template files can override other templates with same name defined by the theme

Interpolation

  • go templates is used control how to content is presented
  • Interpolate and transform dynamic data
{{ define "main" }}
  <h1>List</h1>
  {{ range .Pages }}

  <article>
    <h2>{{ .Title }}</h2>
    {{ .Content }}
  </article>

{{ end }}
// variables
{{ $hello := value }}

// loops
{{ ranger .Pages }}
{{ end }}

// fetch
{{ $myData := getJSON "url" }}

_default

  • The default layout
  • single.html: Single full pages (e.g., about page, blog post)
  • list.html: Page that lists multiple items (e.g., tags page)
<!-- layouts/default/single.html -->
{{ partial "header.html" . - }}
<header>
  <h1>{{ .Title }}</h1>
</header>

<article>
  {{ .Content - }}
</article>

{{ partial "footer.html . }}
<!-- layouts/default/list.html -->
{{ partial "header.html" . -}}

<header>
  <h1 id="tag_{{ .Title }}">{{ .Title | title }}</h1>
</header>

<article>
  {{ .Content - }}

  <ul>
    {{- range.Pages }}
      <li>
        <a href="{{ .RelPermalink }}">{{ .Title }}</a>
        {{ .Summary }}
      </li>
    {{ end -}}
  </ul>
</article>

{{- partial "footer.html" . }}

partials

  • Reusable components that can be used to compose a page
  • E.g., header, footer

shortcodes

  • It's a custom go command that returns a html component
{{
  < img link="https://example.com"
        caption="This is a caption"
        src="/pic.png" >
}}