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

NameContextTypeRequiredDefaultSinceExample
title_separator-string----

Title separator.

title_sections

NameContextTypeRequiredDefaultSinceExample
title_sections-boolean-true--

When false, hide the sections titles.

title_sections_depth

NameContextTypeRequiredDefaultSinceExample
title_sections_depth-number----

The maximum depth of sections.

title_sections_depth_dir

NameContextTypeRequiredDefaultSinceExample
title_sections_depth_dir-string-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  {{ .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 }}

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.