HUGO
News Docs Themes Community GitHub

Single templates

Create a single template to render a single page.

The single template below inherits the site’s shell from the base template.

layouts/_default/single.html
{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}
{{ end }}

Review the template lookup order to select a template path that provides the desired level of specificity.

The single template below inherits the site’s shell from the base template, and renders the page title, creation date, content, and a list of associated terms in the “tags” taxonomy.

layouts/_default/single.html
{{ define "main" }}
  <section>
    <h1>{{ .Title }}</h1>
    {{ with .Date }}
      {{ $dateMachine := . | time.Format "2006-01-02T15:04:05-07:00" }}
      {{ $dateHuman := . | time.Format ":date_long" }}
      <time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
    {{ end }}
    <article>
      {{ .Content }}
    </article>
    <aside>
      {{ with .GetTerms "tags" }}
        <div>{{ (index . 0).Parent.LinkTitle }}</div>
        <ul>
          {{ range . }}
            <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
          {{ end }}
        </ul>
      {{ end }}
    </aside>
  </section>
{{ end }}