Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions content/en/configuration/output-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,7 @@ With `permalinkable` set to true for `json` in the same `page.json.json` templat

## Template lookup order

Each output format requires a template conforming to the [template lookup order][].

For the highest specificity in the template lookup order, include the page kind, output format, and suffix in the file name:

```text
[page kind].[output format].[suffix]
```

For example, for section pages:

Output format|Template path
:--|:--
`html`|`layouts/section.html.html`
`json`|`layouts/section.json.json`
`rss`|`layouts/section.rss.xml`
Each output format requires a template. See [template lookup order][] for template naming and selection rules, including output-format-specific examples.

[`AlternativeOutputFormats`]: /methods/page/alternativeoutputformats/
[`OutputFormats`]: /methods/page/outputformats/
Expand Down
8 changes: 4 additions & 4 deletions content/en/content-management/front-matter.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The most common front matter fields are `date`, `draft`, `title`, and `weight`,
: (`string`) The date that the page was last modified. Note that the TOML format also supports unquoted date/time values. See the [dates](#dates) section for examples. Access this value from a template using the [`Lastmod`][] method on a `Page` object.

`layout`
: (`string`) Provide a template name to [target a specific template][], overriding the default [template lookup order][]. Set the value to the base file name of the template, excluding its extension. Access this value from a template using the [`Layout`][] method on a `Page` object.
: (`string`) A custom layout name to target a specific template. Access this value from a template using the [`Layout`][] method on a `Page` object. See [layout details][] for information on how this field affects template selection.

`linkTitle`
: (`string`) Typically a shorter version of the `title`. Access this value from a template using the [`LinkTitle`][] method on a `Page` object.
Expand Down Expand Up @@ -138,7 +138,7 @@ The most common front matter fields are `date`, `draft`, `title`, and `weight`,
: (`string`) An arbitrary value used to relate two or more translations of the same page, useful when the translated pages do not share a common path. Access this value from a template using the [`TranslationKey`][] method on a `Page` object.

`type`
: (`string`) The [content type](g), overriding the value derived from the top-level section in which the page resides. Access this value from a template using the [`Type`][] method on a `Page` object.
: (`string`) The [content type](g), overriding the value derived from the top-level section in which the page resides. Access this value from a template using the [`Type`][] method on a `Page` object. See [type details][] for information on how this field affects template selection.

`unpublishdate`
: Alias to [expirydate](#expirydate).
Expand Down Expand Up @@ -332,10 +332,10 @@ To override the default time zone, set the [`timeZone`][] in your project config
[content format]: /content-management/formats/
[content formats]: /content-management/formats/#classification
[details]: /configuration/cascade/
[layout details]: /templates/lookup-order/#using-layout
[leaf bundles]: /content-management/page-bundles/#leaf-bundles
[menus]: /content-management/menus/#define-in-front-matter
[output formats]: /configuration/output-formats/
[page resources]: /content-management/page-resources/#metadata
[sitemap templates]: /templates/sitemap/
[target a specific template]: /templates/lookup-order/#target-a-template
[template lookup order]: /templates/lookup-order/
[type details]: /templates/lookup-order/#using-type
39 changes: 10 additions & 29 deletions content/en/content-management/sections.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Sections
description: Organize content into sections.

categories: []
keywords: []
aliases: [/content/sections/]
Expand Down Expand Up @@ -47,7 +46,7 @@ content/
└── about.md
```

The example above has two top-level sections: articles and products. None of the directories under articles are sections, while all of the directories under products are sections. A section within a section is a known as a nested section or subsection.
The example above has two top-level sections: `articles` and `products`. None of the directories under `articles` are sections, while all of the directories under `products` are sections. A section within a section is known as a nested section or subsection.

## Explanation

Expand All @@ -61,30 +60,10 @@ Have list pages|:heavy_check_mark:|:x:

With the file structure from the [example above](#overview):

1. The list page for the articles section includes all articles, regardless of directory structure; none of the subdirectories are sections.
1. The articles/2022 and articles/2023 directories do not have list pages; they are not sections.
1. The list page for the products section, by default, includes product-1 and product-2, but not their descendant pages. To include descendant pages, use the `RegularPagesRecursive` method instead of the `Pages` method in the _section_ template.
1. All directories in the products section have list pages; each directory is a section.

## Template selection

Hugo has a defined [lookup order][] to determine which template to use when rendering a page. The [lookup rules][] consider the top-level section name; subsection names are not considered when selecting a template.

With the file structure from the [example above](#overview):

Content directory|Section template
:--|:--
`content/products`|`layouts/products/section.html`
`content/products/product-1`|`layouts/products/section.html`
`content/products/product-1/benefits`|`layouts/products/section.html`

Content directory|Page template
:--|:--
`content/products`|`layouts/products/page.html`
`content/products/product-1`|`layouts/products/page.html`
`content/products/product-1/benefits`|`layouts/products/page.html`

If you need to use a different template for a subsection, specify `type` and/or `layout` in front matter.
1. The list page for the `articles` section includes all articles, regardless of directory structure; none of the subdirectories are sections.
1. The `articles/2022` and `articles/2023` directories do not have list pages; they are not sections.
1. The list page for the `products` section, by default, includes `product-1` and `product-2`, but not their descendant pages. To include descendant pages, use the [`RegularPagesRecursive`][] method instead of the [`Pages`][] method in the _section_ template.
1. All directories in the `products` section have list pages; each directory is a section.

## Ancestors and descendants

Expand All @@ -94,7 +73,7 @@ A section has one or more ancestors (including the home page), and zero or more
content/products/product-1/benefits/benefit-1.md
```

The content file (benefit-1.md) has four ancestors: benefits, product-1, products, and the home page. This logical relationship allows us to use the `Parent` and `Ancestors` methods to traverse the site structure.
The content file `benefit-1` has four ancestors: `benefits`, `product-1`, `products`, and the home page. This logical relationship allows us to use the [`Parent`][] and [`Ancestors`][] methods to traverse the site structure.

For example, use the `Ancestors` method to render breadcrumb navigation.

Expand Down Expand Up @@ -135,5 +114,7 @@ Hugo renders this, where each breadcrumb is a link to the corresponding page:
Home » Products » Product 1 » Benefits » Benefit 1
```

[lookup order]: /templates/lookup-order/
[lookup rules]: /templates/lookup-order/#lookup-rules
[`Ancestors`]: /methods/page/ancestors/
[`Pages`]: /methods/page/pages/
[`Parent`]: /methods/page/parent/
[`RegularPagesRecursive`]: /methods/page/regularpagesrecursive/
26 changes: 8 additions & 18 deletions content/en/methods/page/Layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,22 @@ params:
signatures: [PAGE.Layout]
---

Specify the `layout` field in front matter to target a particular template. See [details][].
The `Layout` method on a `Page` object returns the layout of the given page as defined by the [`layout`][] field in front matter. If the `layout` field is not defined, the method returns an empty string.

For example, given this front matter:

{{< code-toggle file=content/contact.md fm=true >}}
title = 'Contact'
layout = 'contact'
{{< /code-toggle >}}

Hugo will render the page using contact.html.

```tree
layouts/
├── baseof.html
├── contact.html
├── home.html
├── page.html
├── section.html
├── taxonomy.html
└── term.html
```

Although rarely used within a template, you can access the value with:
Calling the method returns:

```go-html-template
{{ .Layout }}
{{ .Layout }} → contact
```

The `Layout` method returns an empty string if the `layout` field in front matter is not defined.
This method is rarely used within a template. See [details][] for information on how the `layout` field affects template selection.

[details]: /templates/lookup-order/#target-a-template
[`layout`]: /content-management/front-matter/#layout
[details]: /templates/lookup-order/#using-layout
3 changes: 1 addition & 2 deletions content/en/methods/page/Render.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ Although similar to the [`partial`][] function, there are key differences.

`Render` method|`partial` function
:--|:--
The `Page` object is automatically passed to the given template. You cannot pass additional context.|You must specify the context, allowing you to pass a combination of objects, slices, maps, and scalars.
The template is resolved automatically via the [template lookup order][].|You must specify the template name, relative to the `layouts/_partials` directory.
The `Page` object is automatically passed to the given template. You cannot pass additional context.|You must specify the context, allowing you to pass a combination of objects, slices, maps, and scalars. The template is resolved automatically via the [template lookup order][].|You must specify the template name, relative to the `layouts/_partials` directory.

[`partial`]: /functions/partials/include/
[template lookup order]: /templates/lookup-order/
Expand Down
43 changes: 11 additions & 32 deletions content/en/methods/page/Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,22 @@ params:
signatures: [PAGE.Type]
---

The `Type` method on a `Page` object returns the [content type](g) of the given page. The content type is defined by the `type` field in front matter, or inferred from the top-level directory name if the `type` field in front matter is not defined.
The `Type` method on a `Page` object returns the [content type](g) of the given page. The content type is defined by the [`type`][] field in front matter, or inferred from the top-level directory name if the `type` field is not defined.

With this content structure:
For example, given this front matter:

```tree
content/
├── auction/
│ ├── _index.md
│ ├── item-1.md
│ └── item-2.md <-- front matter: type = books
├── books/
│ ├── _index.md
│ ├── book-1.md
│ └── book-2.md
├── films/
│ ├── _index.md
│ ├── film-1.md
│ └── film-2.md
└── _index.md
```
{{< code-toggle file=content/auction/item-1.md fm=true >}}
title = 'Item 1'
type = 'books'
{{< /code-toggle >}}

To list the books, regardless of [section](g):
Calling the method returns:

```go-html-template
{{ range where .Site.RegularPages.ByTitle "Type" "books" }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
```

Hugo renders this to;

```html
<h2><a href="/books/book-1/">Book 1</a></h2>
<h2><a href="/books/book-2/">Book 2</a></h2>
<h2><a href="/auction/item-2/">Item 2</a></h2>
{{ .Type }} → books
```

The `type` field in front matter is also useful for targeting a template. See [details][].
See [details][] for information on how the `type` field affects template selection.

[details]: /templates/lookup-order/#target-a-template
[`type`]: /content-management/front-matter/#type
[details]: /templates/lookup-order/#using-type
4 changes: 3 additions & 1 deletion content/en/quick-reference/glossary/content-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
title: content type
---

A _content type_ is a classification of content inferred from the top-level directory name or the `type` set in [_front matter_](g). Pages in the root of the `content` directory, including the home page, are of type "page". The content type is a contributing factor in the template lookup order and determines which [_archetype_](g) template to use when creating new content.
A _content type_ is a classification of content inferred from the top-level directory name or the `type` set in [_front matter_](g). Pages in the root of the `content` directory, including the home page, are of type "page". The content type is a contributing factor in the [template lookup order][] and determines which [_archetype_](g) template to use when creating new content.

[template lookup order]: /templates/lookup-order/
18 changes: 2 additions & 16 deletions content/en/render-hooks/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,7 @@ layouts/
└── render-table.html
```

The template lookup order allows you to create different render hooks for each page [type](g), [kind](g), language, and [output format](g). For example:

```tree
layouts/
├── _markup/
│ ├── render-link.html
│ └── render-link.rss.xml
├── books/
│ └── _markup/
│ ├── render-link.html
│ └── render-link.rss.xml
└── films/
└── _markup/
├── render-link.html
└── render-link.rss.xml
```
See [template lookup order][] to learn how to target render hook templates by content path, page kind, language, and output format.

The remaining pages in this section describe each type of render hook, including examples and the context received by each template.

Expand All @@ -84,3 +69,4 @@ The remaining pages in this section describe each type of render hook, including
[Passthrough elements]: /render-hooks/passthrough/
[Tables]: /render-hooks/tables/
[content formats]: /content-management/formats/
[template lookup order]: /templates/lookup-order/
2 changes: 0 additions & 2 deletions content/en/templates/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ keywords: []
weight: 10
---

{{< newtemplatesystem >}}

{{% glossary-term template %}}

Templates use [variables](#variables), [functions][], and [methods][] to transform your content, resources, and data into a published page.
Expand Down
Loading
Loading