Title

Template to generate title for pages, that includes separator, paginator (i18n) and section's titles.

Configuration

hugo.yaml

1params:
2  title_sections: true
3  title_separator: '-'

hugo.toml

1[params]
2  title_sections = true
3  title_separator = '-'

hugo.json

1{
2   "params": {
3      "title_sections": true,
4      "title_separator": "-"
5   }
6}

Parameters

title_separator

NameTypeRequiredDefaultSince
title_separatorstring---

Title separator.

title_sections

NameTypeRequiredDefaultSince
title_sectionsboolean-true-

When false, hide the sections titles.

title_sections_depth

NameTypeRequiredDefaultSince
title_sections_depthnumber---

The maximum depth of sections.

title_sections_depth_dir

NameTypeRequiredDefaultSince
title_sections_depth_dirstring-end-

The direction for counting the sections, when start, the depth is counting from the root sections.

Usage

 1{{/* baseof.html */}}
 2<html>
 3  <head>
 4    <title>
 5      {{ block "title" . }}{{ partial "base/title" . }}{{ end }}
 6    </title>
 7  </head>
 8  <body>
 9    {{ block "main" . }}{{ end }}
10  </body>
11</html>
 1{{/* list.html */}}
 2{{ define "title" }}
 3  {{ $mainSections := slice "blog" }}
 4  {{ $pages := where .Site.RegularPages "Type" "in" $mainSections }}
 5  {{/* We MUST initialize the paginator first. */}}
 6  { $paginator := .Paginate $pages 10 }}
 7  {{/* Then include the title partial. */}}
 8  {{ partial "base/title" . }}
 9{{ end }}
10
11{{ define "main" }}
12  {{/* Use the initialized paginator above. */}}
13  {{ range .Paginator.Pages }}
14    {{/* List pages. */}}
15  {{ end }}
16  {{ template "_internal/pagination.html" . }}
17{{ end }}

Examples

PageKindTitle
/HomeMy Site.
/page/1ListMy Site - Page 1 of N.
/page/2ListMy Site - Page 2 of N.
/blogSectionBlog - My Site.
/blog/page/1SectionBlog - Page 1 of N. - My Site.
/blog/page/2SectionBlog - Page 1 of N. - My Site.
/blog/helloPageHello world - Blog - My Site.
/blog/fooSectionFoo - My Site.
/blog/foo/barPageBar - Foo - My Site.