mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'
This commit is contained in:
@@ -39,6 +39,66 @@ Section
|
||||
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:
|
||||
|
||||
```text
|
||||
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:
|
||||
|
||||
[content type]: /getting-started/glossary/#content-type
|
||||
|
||||
```text
|
||||
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 copy=false >}}
|
||||
title = 'Contact'
|
||||
layout = 'contact'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Then create the template for the contact page:
|
||||
|
||||
```text
|
||||
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 copy=false >}}
|
||||
title = 'About'
|
||||
type = 'miscellaneous'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{< code-toggle file=content/contact.md copy=false >}}
|
||||
title = 'Contact'
|
||||
type = 'miscellaneous'
|
||||
layout = 'contact'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Now place the layouts in the corresponding directory:
|
||||
|
||||
```text
|
||||
layouts/
|
||||
└── miscellaneous/
|
||||
└── contact.html <-- renders contact.md
|
||||
└── single.html <-- renders about.md
|
||||
```
|
||||
|
||||
## Home page
|
||||
|
||||
{{< datatable-filtered "output" "layouts" "Kind == home" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
|
||||
|
Reference in New Issue
Block a user