Template to generate title for pages, that includes separator, paginator (i18n) and section's titles.
Become a backer or sponsor to support our work.
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}
title_separator| Name | Context | Type | Required | Default | Since | Example | 
|---|---|---|---|---|---|---|
| title_separator | - | string | - | - | - | - | 
Title separator.
title_sections| Name | Context | Type | Required | Default | Since | Example | 
|---|---|---|---|---|---|---|
| title_sections | - | boolean | - | true | - | - | 
When false, hide the sections titles.
title_sections_depth| Name | Context | Type | Required | Default | Since | Example | 
|---|---|---|---|---|---|---|
| title_sections_depth | - | number | - | - | - | - | 
The maximum depth of sections.
title_sections_depth_dir| Name | Context | Type | Required | Default | Since | Example | 
|---|---|---|---|---|---|---|
| title_sections_depth_dir | - | string | - | end | - | - | 
The direction for counting the sections, when start, the depth is counting from the root sections.
You’ll need to wrap this template as the fallback via block syntax, and initialize the paginator within the title block if necessary, since the .Paginator was cached once initialized, so we MUST initialized it before calling the base/title template, otherwise the paginator will not work as expected.
 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  {{ .Store.Set "paginated" true }} {{/* Indicate current page is a pagination page. */}}
 7  {{ $paginator := .Paginate $pages 10 }}
 8  {{/* Then include the title partial. */}}
 9  {{ partial "base/title" . }}
10{{ end }}
11
12{{ define "main" }}
13  {{/* Use the initialized paginator above. */}}
14  {{ range .Paginator.Pages }}
15    {{/* List pages. */}}
16  {{ end }}
17  {{ template "_internal/pagination.html" . }}
18{{ end }}
| Page | Kind | Title | 
|---|---|---|
| / | Home | My Site. | 
| /page/1 | List | My Site - Page 1 of N. | 
| /page/2 | List | My Site - Page 2 of N. | 
| /blog | Section | Blog - My Site. | 
| /blog/page/1 | Section | Blog - Page 1 of N. - My Site. | 
| /blog/page/2 | Section | Blog - Page 1 of N. - My Site. | 
| /blog/hello | Page | Hello world - Blog - My Site. | 
| /blog/foo | Section | Foo - My Site. | 
| /blog/foo/bar | Page | Bar - Foo - My Site. |