From 7c3adc9ada82e64c41cbd840b867170f748922a3 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sun, 15 Jun 2025 21:01:57 -0700 Subject: [PATCH] content: Change order of template types --- content/en/templates/types.md | 118 +++++++++++++++++----------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/content/en/templates/types.md b/content/en/templates/types.md index e25238365..ca1bb01c1 100644 --- a/content/en/templates/types.md +++ b/content/en/templates/types.md @@ -180,6 +180,65 @@ Within a term template, the [`Data`] object provides these term-specific methods - [`Plural`][term-plural] - [`Term`]. +## Single + +A single template is a fallback for [page templates](#page). If a page template does not exist, Hugo will look for a single template instead. + +Like a page template, a single template renders a regular page. + +For example, the single template below inherits the site's shell from the [base template] and renders the page title and page content. + +```go-html-template {file="layouts/single.html"} +{{ define "main" }} +

{{ .Title }}

+ {{ .Content }} +{{ end }} +``` + +## List + +A list template is a fallback for these template types: [home](#home), [section](#section), [taxonomy](#taxonomy), and [term](#term). If one of these template types does not exist, Hugo will look for a list template instead. + +For example, the list template below inherits the site's shell from the [base template] and renders a list of pages: + +```go-html-template {file="layouts/list.html"} +{{ define "main" }} +

{{ .Title }}

+ {{ .Content }} + {{ range .Pages }} +

{{ .LinkTitle }}

+ {{ end }} +{{ end }} +``` + +## All + +An "all" template is a fallback for these template types: [home](#home), [page](#page), [section](#section), [taxonomy](#taxonomy), [term](#term), [single](#single), and [list](#list). If one of these template types does not exist, Hugo will look for an "all" template instead. + +For example, the contrived "all" template below inherits the site's shell from the [base template] and conditionally renders a page based on its page kind: + +```go-html-template {file="layouts/all.html"} +{{ define "main" }} + {{ if eq .Kind "home" }} + {{ .Content }} + {{ range .Site.RegularPages }} +

{{ .LinkTitle }}

+ {{ end }} + {{ else if eq .Kind "page" }} +

{{ .Title }}

+ {{ .Content }} + {{ else if in (slice "section" "taxonomy" "term") .Kind }} +

{{ .Title }}

+ {{ .Content }} + {{ range .Pages }} +

{{ .LinkTitle }}

+ {{ end }} + {{ else }} + {{ errorf "Unsupported page kind: %s" .Kind }} + {{ end }} +{{ end }} +``` + ## Partial A partial template is typically used to render a component of your site, though you may also create partial templates that return values. @@ -289,65 +348,6 @@ Then call the shortcode from within markup: Learn more about [shortcode templates](/templates/shortcode/). -## Single - -A single template is a fallback for [page templates](#page). If a page template does not exist, Hugo will look for a single template instead. - -Like a page template, a single template renders a regular page. - -For example, the single template below inherits the site's shell from the [base template] and renders the page title and page content. - -```go-html-template {file="layouts/single.html"} -{{ define "main" }} -

{{ .Title }}

- {{ .Content }} -{{ end }} -``` - -## List - -A list template is a fallback for these template types: [home](#home), [section](#section), [taxonomy](#taxonomy), and [term](#term). If one of these template types does not exist, Hugo will look for a list template instead. - -For example, the list template below inherits the site's shell from the [base template] and renders a list of pages: - -```go-html-template {file="layouts/list.html"} -{{ define "main" }} -

{{ .Title }}

- {{ .Content }} - {{ range .Pages }} -

{{ .LinkTitle }}

- {{ end }} -{{ end }} -``` - -## All - -An "all" template is a fallback for these template types: [home](#home), [page](#page), [section](#section), [taxonomy](#taxonomy), [term](#term), [single](#single), and [list](#list). If one of these template types does not exist, Hugo will look for an "all" template instead. - -For example, the contrived "all" template below inherits the site's shell from the [base template] and conditionally renders pages based on page kind: - -```go-html-template {file="layouts/all.html"} -{{ define "main" }} - {{ if eq .Kind "home" }} - {{ .Content }} - {{ range .Site.RegularPages }} -

{{ .LinkTitle }}

- {{ end }} - {{ else if eq .Kind "page" }} -

{{ .Title }}

- {{ .Content }} - {{ else if in (slice "section" "taxonomy" "term") .Kind }} -

{{ .Title }}

- {{ .Content }} - {{ range .Pages }} -

{{ .LinkTitle }}

- {{ end }} - {{ else }} - {{ errorf "Unsupported page kind: %s" .Kind }} - {{ end }} -{{ end }} -``` - ## Other Use other specialized templates to create: