fcc3ed651 Remove some expired new-in a9c5981f5 Fix cascade example 82bb250fa Add some lines about permalinks tokens in front matter 328fe564e Remove some outdated new-in fb140b153 Hide showcase menu entry 42d9d1c79 Update image formats from which EXIF data can be extracted 09ad56b6e netlify: Hugo 0.130.0 1d503f846 Merge branch 'tempv0.130.0' e2458074d math: Add trigonometric functions and some angle helper functions 392afc8f9 Disable the showcase section for now 0300750f2 Improve example of image render hook 60a9306af Improve description of the .Site.RegularPages method 8d759175d Fix typos 55daa4554 Update XxHash.md 397c81cb7 Add namespace for hash functions 70fe8d2f0 netlify: Bump Hugo 0.129.0 5a9771aff Merge branch 'tempv0.129.0' f9146575b Fix typo e6e1fea49 Fix typo in Hugo docs | functions | partial 732d10ec4 source: Expose GitInfo Body 34c97e639 netlify: Hugo 0.128.2 3270587e9 Fix typo 727c5396e netlify: Hugo 0.128.1 80b6ae99c Update GitHub Pages workflow file example 027134102 Update GitHub Pages workflow file example 2600a8a2e Miscellaneous edits 3fdd5819b Update Build.md 7764005c3 Improve example of render hook directory structure 5e3941d82 Fix typos 748bf065f Restructure templates section fafbf6566 Update Defer.md 012162e0d Document changes to template functions in v0.128.0 0990ce35b quick-reference: Update emojis 6677a30ef Update Goldmark configuration documentation 4449d530d Document new pagination config 0af8be439 Update Defer.md 56348196d netlify: Hugo 0.128.0 d67b6d82e Update content/en/functions/templates/Defer.md 23d996b3d Update content/en/functions/templates/Defer.md 7f7fb2f27 Document templates.Defer 5ada1e9d5 Fix docs merge (remove shortcode) d27ee6156 Merge branch 'tempv0.128.0' 5d7317c84 Fix typo 7c18ee546 Update theme 83bfea63b Update theme b274b3238 Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722' ff34a035a deploy: Add stripIndexHtml target option d9e964bdb markup/goldmark: Add the Hugo Goldmark Extras "delete" extension ac5bd16d2 deps: Upgrade github.com/alecthomas/chroma v2.13.0 => v2.14.0 25377171b config: Remove extraneous BuildConfig setting 0d2044f6d docs: Regen docshelper a2548dac9 markup/goldmark: Support extras extension 9d0c86ee8 commands: Add gen chromastyles --lineNumbersTableStyle flag git-subtree-dir: docs git-subtree-split: fcc3ed651a1b6431303c2f88f20fa38531c52b3d
5.5 KiB
title | linkTitle | description | categories | keywords | menu | weight | toc | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Template lookup order | Lookup order | Hugo uses the rules below to select a template for a given page, starting from the most specific. |
|
|
40 | true |
Lookup rules
Hugo takes the parameters listed below into consideration when choosing a template for a given page. The templates are ordered by specificity. This should feel natural, but look at the table below for concrete examples of the different parameter variations.
- Kind
- The page
Kind
(the home page is one). See the example tables below per kind. This also determines if it is a single page (i.e. a regular content page. We then look for a template in_default/single.html
for HTML) or a list page (section listings, home page, taxonomy lists, taxonomy terms. We then look for a template in_default/list.html
for HTML). - Layout
- Can be set in front matter.
- Output Format
- See Custom Output Formats. An output format has both a
name
(e.g.rss
,amp
,html
) and asuffix
(e.g.xml
,html
). We prefer matches with both (e.g.index.amp.html
), but look for less specific templates.
Note that if the output format's Media Type has more than one suffix defined, only the first is considered.
- Language
- We will consider a language tag in the template name. If the site language is
fr
,index.fr.amp.html
will win overindex.amp.html
, butindex.amp.html
will be chosen beforeindex.fr.html
. - Type
- Is value of
type
if set in front matter, else it is the name of the root section (e.g. "blog"). It will always have a value, so if not set, the value is "page". - Section
- Is relevant for
section
,taxonomy
andterm
types.
{{% note %}} Templates can live in either the project's or the themes' layout folders, and the most specific templates will be chosen. Hugo will interleave the lookups listed below, finding the most specific one either in the project or themes. {{% /note %}}
Target a template
You cannot change the lookup order to target a content page, but you can change a content page to target a template. Specify type
, layout
, or both in front matter.
Consider this content structure:
content/
├── about.md
└── contact.md
Files in the root of the content directory have a content type of page
. To render these pages with a unique template, create a matching subdirectory:
layouts/
└── page/
└── single.html
But the contact page probably has a form and requires a different template. In the front matter specify layout
:
{{< code-toggle file=content/contact.md >}} title = 'Contact' layout = 'contact' {{< /code-toggle >}}
Then create the template for the contact page:
layouts/
└── page/
└── contact.html <-- renders contact.md
└── single.html <-- renders about.md
As a content type, the word page
is vague. Perhaps miscellaneous
would be better. Add type
to the front matter of each page:
{{< code-toggle file=content/about.md >}} title = 'About' type = 'miscellaneous' {{< /code-toggle >}}
{{< code-toggle file=content/contact.md >}} title = 'Contact' type = 'miscellaneous' layout = 'contact' {{< /code-toggle >}}
Now place the layouts in the corresponding directory:
layouts/
└── miscellaneous/
└── contact.html <-- renders contact.md
└── single.html <-- renders about.md
Home templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
{{< datatable-filtered "output" "layouts" "Kind == home" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
Single templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
{{< datatable-filtered "output" "layouts" "Kind == page" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
Section templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
{{< datatable-filtered "output" "layouts" "Kind == section" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
Taxonomy templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
The examples below assume the following site configuration:
{{< code-toggle file=hugo >}} [taxonomies] category = 'categories' {{< /code-toggle >}}
{{< datatable-filtered "output" "layouts" "Kind == taxonomy" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
Term templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
The examples below assume the following site configuration:
{{< code-toggle file=hugo >}} [taxonomies] category = 'categories' {{< /code-toggle >}}
{{< datatable-filtered "output" "layouts" "Kind == term" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
RSS templates
These template paths are sorted by specificity in descending order. The least specific path is at the bottom of each list.
The examples below assume the following site configuration:
{{< code-toggle file=hugo >}} [taxonomies] category = 'categories' {{< /code-toggle >}}
{{< datatable-filtered "output" "layouts" "OutputFormat == rss" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}