mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-01 03:02:38 +00:00
Restructure templates section
This commit is contained in:
@@ -15,7 +15,7 @@ aliases: [/gdpr/,/about/hugo-and-gdpr/]
|
||||
|
||||
General Data Protection Regulation ([GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation)) is a regulation in EU law on data protection and privacy for all individuals within the European Union and the European Economic Area. It became enforceable on 25 May 2018.
|
||||
|
||||
**Hugo is a static site generator. By using Hugo you are already standing on very solid ground. Static HTML files on disk are much easier to reason about compared to server and database driven web sites.**
|
||||
**Hugo is a static site generator. By using Hugo you are already standing on very solid ground. Static HTML files on disk are much easier to reason about compared to server and database driven websites.**
|
||||
|
||||
But even static websites can integrate with external services, so from version `0.41`, Hugo provides a **privacy configuration** that covers the relevant built-in templates.
|
||||
|
||||
|
||||
@@ -74,5 +74,5 @@ Open-source commenting systems:
|
||||
[front matter]: /content-management/front-matter/
|
||||
[kaijuissue]: https://github.com/spf13/kaiju/issues/new
|
||||
[issotutorial]: https://stiobhart.net/2017-02-24-isso-comments/
|
||||
[partials]: /templates/partials/
|
||||
[partials]: /templates/partial/
|
||||
[MongoDB]: https://www.mongodb.com/
|
||||
|
||||
@@ -241,7 +241,7 @@ Step 3
|
||||
{{< /code >}}
|
||||
|
||||
Step 4
|
||||
: Create a single page template to render each book review.
|
||||
: Create a single template to render each book review.
|
||||
|
||||
{{< code file=layouts/books/single.html copy=true >}}
|
||||
{{ define "main" }}
|
||||
|
||||
@@ -36,12 +36,12 @@ The `ref` and `relref` shortcodes require a single argument: the path to a conte
|
||||
The pages can be referenced as follows:
|
||||
|
||||
```text
|
||||
{{</* ref "document2" */>}} // <- From pages/document1.md, relative path
|
||||
{{</* ref "document2" */>}} <-- From pages/document1.md, relative path
|
||||
{{</* ref "document2#anchor" */>}}
|
||||
{{</* ref "document2.md" */>}}
|
||||
{{</* ref "document2.md#anchor" */>}}
|
||||
{{</* ref "#anchor" */>}} // <- From pages/document2.md
|
||||
{{</* ref "/blog/my-post" */>}} // <- From anywhere, absolute path
|
||||
{{</* ref "#anchor" */>}} <-- From pages/document2.md
|
||||
{{</* ref "/blog/my-post" */>}} <-- From anywhere, absolute path
|
||||
{{</* ref "/blog/my-post.md" */>}}
|
||||
{{</* relref "document" */>}}
|
||||
{{</* relref "document.md" */>}}
|
||||
@@ -52,12 +52,12 @@ The pages can be referenced as follows:
|
||||
index.md can be reference either by its path or by its containing folder without the ending `/`. \_index.md can be referenced only by its containing folder:
|
||||
|
||||
```text
|
||||
{{</* ref "/about" */>}} // <- References /about/_index.md
|
||||
{{</* ref "/about/_index" */>}} // Raises REF_NOT_FOUND error
|
||||
{{</* ref "/about/credits.md" */>}} // <- References /about/credits.md
|
||||
{{</* ref "/about" */>}} <-- References /about/_index.md
|
||||
{{</* ref "/about/_index" */>}} <-- Raises REF_NOT_FOUND error
|
||||
{{</* ref "/about/credits.md" */>}} <-- References /about/credits.md
|
||||
|
||||
{{</* ref "/products" */>}} // <- References /products/index.md
|
||||
{{</* ref "/products/index" */>}} // <- References /products/index.md
|
||||
{{</* ref "/products" */>}} <-- References /products/index.md
|
||||
{{</* ref "/products/index" */>}} <-- References /products/index.md
|
||||
```
|
||||
|
||||
To generate a hyperlink using `ref` or `relref` in Markdown:
|
||||
@@ -146,7 +146,3 @@ refLinksErrorLevel ("ERROR")
|
||||
|
||||
refLinksNotFoundURL
|
||||
: URL to be used as a placeholder when a page reference cannot be found in `ref` or `relref`. Is used as-is.
|
||||
|
||||
[lists]: /templates/lists/
|
||||
[output formats]: /templates/output-formats/
|
||||
[shortcode]: /content-management/shortcodes/
|
||||
|
||||
@@ -207,7 +207,7 @@ path
|
||||
|
||||
(`map`) A map of sitemap options. See the [sitemap templates] page for details. Access these values from a template using the [`Sitemap`] method on a `Page` object.
|
||||
|
||||
[sitemap templates]: /templates/sitemap-template/
|
||||
[sitemap templates]: /templates/sitemap/
|
||||
[`sitemap`]: /methods/page/sitemap/
|
||||
|
||||
###### slug
|
||||
|
||||
@@ -59,7 +59,7 @@ A remote resource is a file on a remote server, accessible via HTTP or HTTPS. To
|
||||
|
||||
## Image rendering
|
||||
|
||||
Once you have accessed an image as either a page resource or a global resource, render it in your templates using the `Permalink`, `RelPermalink`, `Width`, and `Height` properties.
|
||||
Once you have accessed an image as a resource, render it in your templates using the `Permalink`, `RelPermalink`, `Width`, and `Height` properties.
|
||||
|
||||
Example 1: Throws an error if the resource is not found.
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ Hugo provides two methods to localize your menu entries. See [multilingual].
|
||||
See [menu templates].
|
||||
|
||||
[localize]: /content-management/multilingual/#menus
|
||||
[menu templates]: /templates/menu-templates/
|
||||
[menu templates]: /templates/menu/
|
||||
[multilingual]: /content-management/multilingual/#menus
|
||||
[section]: /getting-started/glossary/#section
|
||||
[template]: /templates/menu-templates/
|
||||
[template]: /templates/menu/
|
||||
|
||||
@@ -322,7 +322,7 @@ To create a list of links to translated content, use a template similar to the f
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
The above can be put in a `partial` (i.e., inside `layouts/partials/`) and included in any template, whether a [single content page][contenttemplate] or the [homepage]. It will not print anything if there are no translations for a given page.
|
||||
The above can be put in a `partial` (i.e., inside `layouts/partials/`) and included in any template. It will not print anything if there are no translations for a given page.
|
||||
|
||||
The above also uses the [`i18n` function][i18func] described in the next section.
|
||||
|
||||
@@ -564,7 +564,7 @@ products = 'Produkte'
|
||||
services = 'Leistungen'
|
||||
{{< / code-toggle >}}
|
||||
|
||||
[example menu template]: /templates/menu-templates/#example
|
||||
[example menu template]: /templates/menu/#example
|
||||
[automatically]: /content-management/menus/#define-automatically
|
||||
[in front matter]: /content-management/menus/#define-in-front-matter
|
||||
[in site configuration]: /content-management/menus/#define-in-site-configuration
|
||||
@@ -615,10 +615,8 @@ hugo new content content/de/post/test.md
|
||||
|
||||
[`abslangurl`]: /functions/urls/abslangurl/
|
||||
[config]: /getting-started/configuration/
|
||||
[contenttemplate]: /templates/single-page-templates/
|
||||
[go-i18n-source]: https://github.com/nicksnyder/go-i18n
|
||||
[go-i18n]: https://github.com/nicksnyder/go-i18n
|
||||
[homepage]: /templates/homepage/
|
||||
[Hugo Multilingual Part 1: Content translation]: https://regisphilibert.com/blog/2018/08/hugo-multilingual-part-1-managing-content-translation/
|
||||
[i18func]: /functions/lang/translate/
|
||||
[lang.FormatAccounting]: /functions/lang/formataccounting/
|
||||
@@ -630,5 +628,4 @@ hugo new content content/de/post/test.md
|
||||
[menus]: /content-management/menus/
|
||||
[OS environment]: /getting-started/configuration/#configure-with-environment-variables
|
||||
[`rellangurl`]: /functions/urls/rellangurl/
|
||||
[single page templates]: /templates/single-page-templates/
|
||||
[`time.Format`]: /functions/time/format/
|
||||
|
||||
@@ -71,13 +71,13 @@ The following demonstrates the relationships between your content organization a
|
||||
|
||||
### Index pages: `_index.md`
|
||||
|
||||
`_index.md` has a special role in Hugo. It allows you to add front matter and content to your [list templates][lists]. These templates include those for [section templates], [taxonomy templates], [taxonomy terms templates], and your [homepage template].
|
||||
`_index.md` has a special role in Hugo. It allows you to add front matter and content to `home`, `section`, `taxonomy`, and `term` pages.
|
||||
|
||||
{{% note %}}
|
||||
**Tip:** You can get a reference to the content and metadata in `_index.md` using the [`.Site.GetPage` function](/methods/page/getpage).
|
||||
{{% /note %}}
|
||||
|
||||
You can create one `_index.md` for your homepage and one in each of your content sections, taxonomies, and taxonomy terms. The following shows typical placement of an `_index.md` that would contain content and front matter for a `posts` section list page on a Hugo website:
|
||||
You can create one `_index.md` for your home page and one in each of your content sections, taxonomies, and terms. The following shows typical placement of an `_index.md` that would contain content and front matter for a `posts` section list page on a Hugo website:
|
||||
|
||||
```txt
|
||||
. url
|
||||
@@ -106,7 +106,7 @@ The [sections] can be nested as deeply as you want. The important thing to under
|
||||
|
||||
### Single pages in sections
|
||||
|
||||
Single content files in each of your sections will be rendered as [single page templates][singles]. Here is an example of a single `post` within `posts`:
|
||||
Single content files in each of your sections will be rendered by a [single template]. Here is an example of a single `post` within `posts`:
|
||||
|
||||
```txt
|
||||
path ("posts/my-first-hugo-post.md")
|
||||
@@ -156,14 +156,7 @@ The `url` is the entire URL path, defined by the file path and optionally overri
|
||||
[formats]: /content-management/formats/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[getpage]: /methods/page/getpage/
|
||||
[homepage template]: /templates/homepage/
|
||||
[homepage]: /templates/homepage/
|
||||
[lists]: /templates/lists/
|
||||
[pretty]: /content-management/urls/#appearance
|
||||
[section templates]: /templates/section-templates/
|
||||
[sections]: /content-management/sections/
|
||||
[singles]: /templates/single-page-templates/
|
||||
[taxonomy templates]: /templates/taxonomy-templates/
|
||||
[taxonomy terms templates]: /templates/taxonomy-templates/
|
||||
[types]: /content-management/types/
|
||||
[single template]: /templates/types/#single
|
||||
[urls]: /content-management/urls/
|
||||
|
||||
@@ -50,11 +50,17 @@ Page bundle characteristics vary by bundle type.
|
||||
| Index file | index.md | _index.md |
|
||||
| Example | content/about/index.md | content/posts/_index.md |
|
||||
| [Page kinds] | `page` | `home`, `section`, `taxonomy`, or `term` |
|
||||
| Layout type | [single] | [list] |
|
||||
| Template types | [single] | [home], [section], [taxonomy], or [term] |
|
||||
| Descendant pages | None | Zero or more |
|
||||
| Resource location | Adjacent to the index file or in a nested subdirectory | Same as a leaf bundles, but excludes descendant bundles |
|
||||
| [Resource types] | `page`, `image`, `video`, etc. | all but `page` |
|
||||
|
||||
[single]: /templates/types/#single
|
||||
[home]: /templates/types/#home
|
||||
[section]: /templates/types/#section
|
||||
[taxonomy]: /templates/types/#taxonomy
|
||||
[term]: /templates/types/#term
|
||||
|
||||
Files with [resource type] `page` include content written in Markdown, HTML, AsciiDoc, Pandoc, reStructuredText, and Emacs Org Mode. In a leaf bundle, excluding the index file, these files are only accessible as page resources. In a branch bundle, these files are only accessible as content pages.
|
||||
|
||||
## Leaf bundles
|
||||
@@ -149,9 +155,7 @@ Use [build options] in front matter to create an unpublished leaf or branch bund
|
||||
|
||||
[`Resources`]: /methods/page/resources/
|
||||
[build options]: content-management/build-options/
|
||||
[list]: /templates/lists/
|
||||
[page kinds]: /getting-started/glossary/#page-kind
|
||||
[page resources]: /content-management/page-resources/
|
||||
[resource type]: /getting-started/glossary/#resource-type
|
||||
[resource types]: /getting-started/glossary/#resource-type
|
||||
[single]: /templates/single-page-templates/
|
||||
|
||||
@@ -16,7 +16,7 @@ Hugo uses a set of factors to identify a page's related content based on front m
|
||||
|
||||
## List related content
|
||||
|
||||
To list up to 5 related pages (which share the same _date_ or _keyword_ parameters) is as simple as including something similar to this partial in your single page template:
|
||||
To list up to 5 related pages (which share the same _date_ or _keyword_ parameters) is as simple as including something similar to this partial in your template:
|
||||
|
||||
{{< code file=layouts/partials/related.html >}}
|
||||
{{ $related := .Site.RegularPages.Related . | first 5 }}
|
||||
|
||||
@@ -90,13 +90,13 @@ Hugo has a defined [lookup order] to determine which template to use when render
|
||||
|
||||
With the file structure from the [example above](#overview):
|
||||
|
||||
Content directory|List page template
|
||||
Content directory|Section template
|
||||
:--|:--
|
||||
content/products|layouts/products/list.html
|
||||
content/products/product-1|layouts/products/list.html
|
||||
content/products/product-1/benefits|layouts/products/list.html
|
||||
|
||||
Content directory|Single page template
|
||||
Content directory|Single template
|
||||
:--|:--
|
||||
content/products|layouts/products/single.html
|
||||
content/products/product-1|layouts/products/single.html
|
||||
@@ -159,6 +159,6 @@ Home » Products » Product 1 » Benefits » Benefit 1
|
||||
[archetype]: /content-management/archetypes/
|
||||
[content type]: /content-management/types/
|
||||
[directory structure]: /getting-started/directory-structure/
|
||||
[section templates]: /templates/section-templates/
|
||||
[section templates]: /templates/types/#section
|
||||
[leaf bundles]: /content-management/page-bundles/#leaf-bundles
|
||||
[branch bundles]: /content-management/page-bundles/#branch-bundles
|
||||
|
||||
@@ -469,9 +469,9 @@ To learn how to configure your Hugo site to meet the new EU privacy regulation,
|
||||
To learn more about creating custom shortcodes, see the [shortcode template documentation].
|
||||
|
||||
[privacy protections]: /about/privacy/
|
||||
[partials]: /templates/partials/
|
||||
[partials]: /templates/partial/
|
||||
[quickstart]: /getting-started/quick-start/
|
||||
[sctemps]: /templates/shortcode-templates/
|
||||
[shortcode template documentation]: /templates/shortcode-templates/
|
||||
[sctemps]: /templates/shortcode/
|
||||
[shortcode template documentation]: /templates/shortcode/
|
||||
[Vimeo]: https://vimeo.com/
|
||||
[YouTube Videos]: https://www.youtube.com/
|
||||
|
||||
@@ -95,7 +95,7 @@ disableKinds = ["taxonomy","term"]
|
||||
|
||||
When taxonomies are used---and [taxonomy templates] are provided---Hugo will automatically create both a page listing all the taxonomy's terms and individual pages with lists of content associated with each term. For example, a `categories` taxonomy declared in your configuration and used in your content front matter will create the following pages:
|
||||
|
||||
* A single page at `example.com/categories/` that lists all the [terms within the taxonomy]
|
||||
* A single page at `example.com/categories/` that lists all the terms within the taxonomy
|
||||
* [Individual taxonomy list pages][taxonomy templates] (e.g., `/categories/development/`) for each of the terms that shows a listing of all pages marked as part of that taxonomy within any content file's [front matter]
|
||||
|
||||
## Configure taxonomies
|
||||
@@ -142,7 +142,7 @@ categories = ['Category A','Category B']
|
||||
|
||||
## Order taxonomies
|
||||
|
||||
A content file can assign weight for each of its associate taxonomies. Taxonomic weight can be used for sorting or ordering content in [taxonomy list templates] and is declared in a content file's [front matter]. The convention for declaring taxonomic weight is `taxonomyname_weight`.
|
||||
A content file can assign weight for each of its associate taxonomies. Taxonomic weight can be used for sorting or ordering content in [taxonomy templates] and is declared in a content file's [front matter]. The convention for declaring taxonomic weight is `taxonomyname_weight`.
|
||||
|
||||
The following show a piece of content that has a weight of 22, which can be used for ordering purposes when rendering the pages assigned to the "a", "b" and "c" values of the `tags` taxonomy. It has also been assigned the weight of 44 when rendering the "d" category page.
|
||||
|
||||
@@ -171,7 +171,5 @@ wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
|
||||
[content type]: /content-management/types/
|
||||
[documentation on archetypes]: /content-management/archetypes/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[taxonomy list templates]: /templates/taxonomy-templates/#taxonomy-templates
|
||||
[taxonomy templates]: /templates/taxonomy-templates/
|
||||
[terms within the taxonomy]: /templates/taxonomy-templates/#term-templates
|
||||
[taxonomy templates]: /templates/types/#taxonomy
|
||||
[site configuration]: /getting-started/configuration/
|
||||
|
||||
@@ -16,5 +16,5 @@ A **content type** is a way to organize your content. Hugo resolves the content
|
||||
|
||||
A content type is used to
|
||||
|
||||
- Determine how the content is rendered. See [Template Lookup Order](/templates/lookup-order/) and [Content Views](/templates/views) for more.
|
||||
- Determine how the content is rendered. See [Template Lookup Order](/templates/lookup-order/) and [Content Views](/templates/content-view) for more.
|
||||
- Determine which [archetype](/content-management/archetypes/) template to use for new content.
|
||||
|
||||
@@ -158,7 +158,7 @@ CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest
|
||||
To build and install a specific release:
|
||||
|
||||
```sh
|
||||
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@v0.126.0
|
||||
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@v0.128.0
|
||||
```
|
||||
|
||||
To build and install at the latest commit on the master branch:
|
||||
|
||||
@@ -44,6 +44,8 @@ Although we do not strictly adhere to the [Microsoft Writing Style Guide], it is
|
||||
Please link to the [glossary of terms] when necessary, and use the terms consistently throughout the documentation. Of special note:
|
||||
|
||||
- The term "front matter" is two words unless you are referring to the configuration key
|
||||
- The term "home page" is two words
|
||||
- The term "website" is one word
|
||||
- The term "standalone" is one word, not hyphenated
|
||||
- Use the word "map" instead of "dictionary"
|
||||
- Use the word "flag" instead of "option" when referring to a command line flag
|
||||
|
||||
@@ -35,7 +35,7 @@ The template above is rendered to:
|
||||
|
||||
## Example of `after` with `first`: 2nd–4th most recent articles
|
||||
|
||||
You can use `after` in combination with the [`first`] function and Hugo's [powerful sorting methods][lists]. Let's assume you have a list page at `example.com/articles`. You have 10 articles, but you want your templating for the [list/section page] to show only two rows:
|
||||
You can use `after` in combination with the [`first`] function and Hugo's [powerful sorting methods](/quick-reference/page-collections/#sort). Let's assume you have a `section` page at `example.com/articles`. You have 10 articles, but you want your template to show only two rows:
|
||||
|
||||
1. The top row is titled "Featured" and shows only the most recently published article (i.e. by `publishdate` in the content files' front matter).
|
||||
2. The second row is titled "Recent Articles" and shows only the 2nd- to 4th-most recently published articles.
|
||||
@@ -66,6 +66,4 @@ You can use `after` in combination with the [`first`] function and Hugo's [power
|
||||
{{< /code >}}
|
||||
|
||||
[`first`]: /functions/collections/first/
|
||||
[list/section page]: /templates/section-templates/
|
||||
[lists]: /templates/lists/#sort-content
|
||||
[`slice`]: /functions/collections/slice/
|
||||
|
||||
@@ -28,4 +28,4 @@ aliases: [/functions/group]
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
The page group you get from `group` is of the same type you get from the built-in [group methods](/templates/lists#group-content) in Hugo. The example above can be [paginated](/templates/pagination/).
|
||||
The page group you get from `group` is of the same type you get from the built-in [group methods](/quick-reference/page-collections/#group) in Hugo. The example above can be [paginated](/templates/pagination/).
|
||||
|
||||
@@ -25,6 +25,3 @@ A useful example is to use it as `AND` filters when combined with where:
|
||||
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
|
||||
|
||||
See [union](/functions/collections/union) for `OR`.
|
||||
|
||||
[partials]: /templates/partials/
|
||||
[single]: /templates/single-page-templates/
|
||||
|
||||
@@ -15,8 +15,6 @@ action:
|
||||
aliases: [/functions/crypto.fnv32a]
|
||||
---
|
||||
|
||||
{{< new-in 0.98.0 >}}
|
||||
|
||||
This function calculates the 32-bit [FNV1a hash](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) of a given string according to the [specification](https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-12):
|
||||
|
||||
```go-html-template
|
||||
|
||||
@@ -141,8 +141,8 @@ To install Dart Sass for your builds on GitLab Pages, the `.gitlab-ci.yml` file
|
||||
|
||||
```yaml
|
||||
variables:
|
||||
HUGO_VERSION: 0.126.0
|
||||
DART_SASS_VERSION: 1.77.1
|
||||
HUGO_VERSION: 0.128.0
|
||||
DART_SASS_VERSION: 1.77.5
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
@@ -175,8 +175,8 @@ To install Dart Sass for your builds on Netlify, the `netlify.toml` file should
|
||||
|
||||
```toml
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.126.0"
|
||||
DART_SASS_VERSION = "1.77.1"
|
||||
HUGO_VERSION = "0.128.0"
|
||||
DART_SASS_VERSION = "1.77.5"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
[build]
|
||||
|
||||
@@ -79,3 +79,7 @@ Process the resource:
|
||||
```
|
||||
|
||||
The example above publishes the minified CSS file to public/css/main.css.
|
||||
|
||||
See [this repository] for more information about the integration with Tailwind CSS v4.0.
|
||||
|
||||
[this repository]: https://github.com/bep/hugo-testing-tailwindcss-v4
|
||||
|
||||
@@ -58,7 +58,7 @@ content/
|
||||
└── _index.md <-- title is "My Home Page"
|
||||
```
|
||||
|
||||
And this code in the home page template:
|
||||
And this code in the home template:
|
||||
|
||||
```go-html-template
|
||||
{{ range site.Sections }}
|
||||
@@ -76,7 +76,7 @@ My Home Page
|
||||
My Home Page
|
||||
```
|
||||
|
||||
In the example above, the global `page` function accesses the `Page` object passed into the home page template; it does not access the `Page` object of the iterated pages.
|
||||
In the example above, the global `page` function accesses the `Page` object passed into the home template; it does not access the `Page` object of the iterated pages.
|
||||
|
||||
### Be aware of caching
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ Hugo renders:
|
||||
|
||||
See additional examples in the [partial templates] section.
|
||||
|
||||
[partial templates]: /templates/partials/#returning-a-value-from-a-partial
|
||||
[partial templates]: /templates/partial/#returning-a-value-from-a-partial
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -45,5 +45,5 @@ The example above can be rewritten using an [inline partial] template:
|
||||
{{% include "functions/go-template/_common/text-template.md" %}}
|
||||
|
||||
[`partial`]: /functions/partials/include/
|
||||
[inline partial]: /templates/partials/#inline-partials
|
||||
[inline partial]: /templates/partial/#inline-partials
|
||||
[embedded templates]: /templates/embedded/
|
||||
|
||||
@@ -11,5 +11,5 @@ action:
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ hugo.Generator }} → <meta name="generator" content="Hugo 0.126.0">
|
||||
{{ hugo.Generator }} → <meta name="generator" content="Hugo 0.128.0">
|
||||
```
|
||||
|
||||
@@ -11,5 +11,5 @@ action:
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ hugo.Version }} → 0.126.0
|
||||
{{ hugo.Version }} → 0.128.0
|
||||
```
|
||||
|
||||
@@ -26,7 +26,7 @@ The [media type] is typically one of `image`, `text`, `audio`, `video`, or `appl
|
||||
{{% note %}}
|
||||
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
|
||||
|
||||
For page resources, use the [`Resources.ByType`] method on the Page object.
|
||||
For page resources, use the [`Resources.ByType`] method on a `Page` object.
|
||||
|
||||
[`Resources.ByType`]: /methods/page/resources/
|
||||
{{% /note %}}
|
||||
|
||||
@@ -24,7 +24,7 @@ Let's say you need to publish a file named "site.json" in the root of your publi
|
||||
```json
|
||||
{
|
||||
"build_date": "2024-02-19T12:27:05-08:00",
|
||||
"hugo_version": "0.126.0",
|
||||
"hugo_version": "0.128.0",
|
||||
"last_modified": "2024-02-19T12:01:42-08:00"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -24,7 +24,7 @@ action:
|
||||
{{% note %}}
|
||||
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
|
||||
|
||||
For page resources, use the [`Resources.Get`] method on the Page object.
|
||||
For page resources, use the [`Resources.Get`] method on a `Page` object.
|
||||
|
||||
[`Resources.Get`]: /methods/page/resources/
|
||||
{{% /note %}}
|
||||
|
||||
@@ -24,7 +24,7 @@ action:
|
||||
{{% note %}}
|
||||
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
|
||||
|
||||
For page resources, use the [`Resources.GetMatch`] method on the Page object.
|
||||
For page resources, use the [`Resources.GetMatch`] method on a `Page` object.
|
||||
|
||||
[`Resources.GetMatch`]: /methods/page/resources/
|
||||
{{% /note %}}
|
||||
|
||||
@@ -24,7 +24,7 @@ action:
|
||||
{{% note %}}
|
||||
This function operates on global resources. A global resource is a file within the assets directory, or within any directory mounted to the assets directory.
|
||||
|
||||
For page resources, use the [`Resources.Match`] method on the Page object.
|
||||
For page resources, use the [`Resources.Match`] method on a `Page` object.
|
||||
|
||||
[`Resources.Match`]: /methods/page/resources/
|
||||
{{% /note %}}
|
||||
|
||||
@@ -146,8 +146,8 @@ To install Dart Sass for your builds on GitLab Pages, the `.gitlab-ci.yml` file
|
||||
|
||||
```yaml
|
||||
variables:
|
||||
HUGO_VERSION: 0.126.0
|
||||
DART_SASS_VERSION: 1.77.1
|
||||
HUGO_VERSION: 0.128.0
|
||||
DART_SASS_VERSION: 1.77.5
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
@@ -180,8 +180,8 @@ To install Dart Sass for your builds on Netlify, the `netlify.toml` file should
|
||||
|
||||
```toml
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.126.0"
|
||||
DART_SASS_VERSION = "1.77.1"
|
||||
HUGO_VERSION = "0.128.0"
|
||||
DART_SASS_VERSION = "1.77.5"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
[build]
|
||||
|
||||
@@ -26,5 +26,5 @@ I :heart: Hugo!
|
||||
|
||||
[configuration]: /getting-started/configuration/
|
||||
[emoji shortcodes]: /quick-reference/emojis/
|
||||
[sc]: /templates/shortcode-templates/
|
||||
[sc]: /templates/shortcode/
|
||||
[scsource]: https://github.com/gohugoio/hugo/tree/master/docs/layouts/shortcodes
|
||||
|
||||
@@ -438,7 +438,7 @@ See [Segments](#configure-segments).
|
||||
|
||||
###### sitemap
|
||||
|
||||
Default [sitemap configuration](/templates/sitemap-template/#configuration).
|
||||
Default [sitemap configuration](/templates/sitemap/#configuration).
|
||||
|
||||
###### summaryLength
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ A classification of content inferred from the top-level directory name or the `t
|
||||
|
||||
###### content view
|
||||
|
||||
A template called with the `.Page.Render` method. See [details](/templates/views/).
|
||||
A template called with the `.Page.Render` method. See [details](/templates/content-view/).
|
||||
|
||||
###### context
|
||||
|
||||
@@ -132,7 +132,6 @@ To determine the current environment within a template, use the [`hugo.Environme
|
||||
|
||||
A predefined key-value pair in front matter such as `date` or `title`. See also [parameter](#parameter).
|
||||
|
||||
|
||||
###### flag
|
||||
|
||||
An option passed to a command-line program, beginning with one or two hyphens. See [details](/commands/hugo/).
|
||||
@@ -212,6 +211,10 @@ A directory that contains an index.md file and zero or more [resources](#resourc
|
||||
|
||||
Any [page kind](#page-kind) that receives a page [collection](#collection) in [context](#context). This includes the home page, [section pages](#section-page), [taxonomy pages](#taxonomy-page), and [term pages](#term-page).
|
||||
|
||||
###### list template
|
||||
|
||||
Any template that renders a [list page](#list-page). This includes [home](/templates/types/#home), [section](/templates/types/#section), [taxonomy](/templates/types/#taxonomy), and [term](/templates/types/#term) templates.
|
||||
|
||||
###### localization
|
||||
|
||||
Adaptation of a site to meet language and regional requirements. This includes translations, language-specific media, date and currency formats, etc. See [details](/content-management/multilingual/) and the [W3C definition](https://www.w3.org/International/questions/qa-i18n). Abbreviated l10n.
|
||||
@@ -256,7 +259,7 @@ A data structure with or without associated [methods](#method).
|
||||
|
||||
###### ordered taxonomy
|
||||
|
||||
Created by invoking the [`Alphabetical`] or [`ByCount`] method on a [taxonomy object](#taxonomy-object), which is a [map](#map), an ordered taxonomy is a [slice](#slice), where each element is an object that contains the [term](#term) and a slice of its [weighted pages](#weighted-page).
|
||||
Created by invoking the [`Alphabetical`] or [`ByCount`] method on a [`Taxonomy`](#taxonomy-object) object, which is a [map](#map), an ordered taxonomy is a [slice](#slice), where each element is an object that contains the [term](#term) and a slice of its [weighted pages](#weighted-page).
|
||||
|
||||
[`Alphabetical`]: /methods/taxonomy/alphabetical/
|
||||
[`ByCount`]: /methods/taxonomy/bycount/
|
||||
@@ -271,7 +274,7 @@ A directory that encapsulates both content and associated [resources](#resource)
|
||||
|
||||
###### page collection
|
||||
|
||||
A slice of page objects.
|
||||
A slice of `Page` objects.
|
||||
|
||||
###### page kind
|
||||
|
||||
@@ -398,7 +401,7 @@ Raw string literals are character sequences between backticks, as in \`bar\`. Wi
|
||||
|
||||
###### taxonomic weight
|
||||
|
||||
Defined in front matter and unique to each taxonomy, this [weight](#weight) determines the sort order of page collections contained within a [taxonomy object](#taxonomy-object). See [details](/templates/taxonomy-templates/#assign-weight).
|
||||
Defined in front matter and unique to each taxonomy, this [weight](#weight) determines the sort order of page collections contained within a [`Taxonomy`](#taxonomy-object) object. See [details](/content-management/taxonomies/#order-taxonomies).
|
||||
|
||||
###### taxonomy
|
||||
|
||||
@@ -458,7 +461,7 @@ Used to position an element within a collection sorted by weight. Assign weights
|
||||
|
||||
###### weighted page
|
||||
|
||||
Contained within a [taxonomy object](#taxonomy-object), a weighted page is a [map](#map) with two elements: a `Page` object, and its [taxonomic weight](#taxonomic-weight) as defined in front matter. Access the elements using the `Page` and `Weight` keys.
|
||||
Contained within a [`Taxonomy`](#taxonomy-object) object, a weighted page is a [map](#map) with two elements: a `Page` object, and its [taxonomic weight](#taxonomic-weight) as defined in front matter. Access the elements using the `Page` and `Weight` keys.
|
||||
|
||||
###### zero time
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ Add the following content. Replace the `USER`, `HOST`, and `DIR` values with you
|
||||
#!/bin/sh
|
||||
USER=my-user
|
||||
HOST=my-server.com
|
||||
DIR=my/directory/to/topologix.fr/ # the directory where your web site files should go
|
||||
DIR=my/directory/to/topologix.fr/ # the directory where your website files should go
|
||||
|
||||
hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR} # this will delete everything on the server that's not in the local public folder
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
HUGO_VERSION: 0.127.0
|
||||
HUGO_VERSION: 0.128.0
|
||||
steps:
|
||||
- name: Install Hugo CLI
|
||||
run: |
|
||||
|
||||
@@ -27,8 +27,8 @@ Define your [CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) jobs by creating
|
||||
|
||||
{{< code file=.gitlab-ci.yml copy=true >}}
|
||||
variables:
|
||||
DART_SASS_VERSION: 1.77.1
|
||||
HUGO_VERSION: 0.126.0
|
||||
DART_SASS_VERSION: 1.77.5
|
||||
HUGO_VERSION: 0.128.0
|
||||
NODE_VERSION: 20.x
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
|
||||
@@ -101,7 +101,7 @@ Create a new file named netlify.toml in the root of your project directory. In i
|
||||
|
||||
{{< code file=netlify.toml >}}
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.126.0"
|
||||
HUGO_VERSION = "0.128.0"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
[build]
|
||||
@@ -113,8 +113,8 @@ If your site requires Dart Sass to transpile Sass to CSS, the configuration file
|
||||
|
||||
{{< code file=netlify.toml >}}
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.126.0"
|
||||
DART_SASS_VERSION = "1.77.1"
|
||||
HUGO_VERSION = "0.128.0"
|
||||
DART_SASS_VERSION = "1.77.5"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
[build]
|
||||
|
||||
@@ -136,8 +136,8 @@ To install Dart Sass for your builds on GitLab Pages, the `.gitlab-ci.yml` file
|
||||
|
||||
```yaml
|
||||
variables:
|
||||
HUGO_VERSION: 0.126.0
|
||||
DART_SASS_VERSION: 1.77.1
|
||||
HUGO_VERSION: 0.128.0
|
||||
DART_SASS_VERSION: 1.77.5
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
@@ -170,8 +170,8 @@ To install Dart Sass for your builds on Netlify, the `netlify.toml` file should
|
||||
|
||||
```toml
|
||||
[build.environment]
|
||||
HUGO_VERSION = "0.122.2"
|
||||
DART_SASS_VERSION = "1.77.1"
|
||||
HUGO_VERSION = "0.128.0"
|
||||
DART_SASS_VERSION = "1.77.5"
|
||||
TZ = "America/Los_Angeles"
|
||||
|
||||
[build]
|
||||
|
||||
@@ -21,4 +21,4 @@ Use this method with the [`IsMenuCurrent`] and [`HasMenuCurrent`] methods on a `
|
||||
|
||||
[`HasMenuCurrent`]: /methods/page/hasmenucurrent/
|
||||
[`IsMenuCurrent`]: /methods/page/ismenucurrent/
|
||||
[this example]: /templates/menu-templates/#example
|
||||
[this example]: /templates/menu/#example
|
||||
|
||||
@@ -49,5 +49,5 @@ See the [menu templates] section for more information.
|
||||
[`LinkTitle`]: /methods/page/linktitle/
|
||||
[`RelPermalink`]: /methods/page/relpermalink/
|
||||
[define menu entries]: /content-management/menus/
|
||||
[menu templates]: /templates/menu-templates/#page-references
|
||||
[menu templates]: /templates/menu/#page-references
|
||||
[methods]: /methods/page/
|
||||
|
||||
@@ -57,6 +57,6 @@ Hugo renders:
|
||||
|
||||
See the [menu templates] section for more information.
|
||||
|
||||
[menu templates]: /templates/menu-templates/#menu-entry-parameters
|
||||
[menu templates]: /templates/menu/#menu-entry-parameters
|
||||
[in front matter]: /content-management/menus/#define-in-front-matter
|
||||
[in site configuration]: /content-management/menus/
|
||||
|
||||
@@ -65,14 +65,14 @@ Plural
|
||||
```
|
||||
|
||||
Terms
|
||||
: (`page.Taxonomy`) Returns the taxonomy object, consisting of a map of terms and the [weighted pages] associated with each term.
|
||||
: (`page.Taxonomy`) Returns the `Taxonomy` object, consisting of a map of terms and the [weighted pages] associated with each term.
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomyObject := .Data.Terms }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Once you have captured the taxonomy object, use any of the [taxonomy methods] to sort, count, or capture a subset of its weighted pages.
|
||||
Once you have captured the `Taxonomy` object, use any of the [taxonomy methods] to sort, count, or capture a subset of its weighted pages.
|
||||
|
||||
[taxonomy methods]: /methods/taxonomy/
|
||||
{{% /note %}}
|
||||
@@ -106,6 +106,6 @@ Term
|
||||
|
||||
Learn more about [term templates].
|
||||
|
||||
[taxonomy templates]: /templates/taxonomy-templates/
|
||||
[term templates]: /templates/taxonomy-templates/
|
||||
[taxonomy templates]: /templates/types/#taxonomy
|
||||
[term templates]: /templates/types/#term
|
||||
[weighted pages]: /getting-started/glossary/#weighted-page
|
||||
|
||||
@@ -9,7 +9,7 @@ action:
|
||||
signatures: [PAGE1.Eq PAGE2]
|
||||
---
|
||||
|
||||
In this contrived example from a single page template, we list all pages in the current section except for the current page.
|
||||
In this contrived example from a single template, we list all pages in the current section except for the current page.
|
||||
|
||||
```go-html-template
|
||||
{{ $currentPage := . }}
|
||||
|
||||
@@ -36,9 +36,9 @@ content/
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
The examples below depict the result of rendering works/paintings/the-mona-lisa.md with a single page template:
|
||||
The examples below depict the result of rendering works/paintings/the-mona-lisa.md:
|
||||
|
||||
```go-html-template
|
||||
{{< code file=layouts/works/single.html >}}
|
||||
{{ with .GetPage "starry-night" }}
|
||||
{{ .Title }} → Starry Night
|
||||
{{ end }}
|
||||
@@ -62,4 +62,4 @@ The examples below depict the result of rendering works/paintings/the-mona-lisa.
|
||||
{{ with .GetPage "/works/sculptures/david" }}
|
||||
{{ .Title }} → David
|
||||
{{ end }}
|
||||
```
|
||||
{{< /code >}}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: HasMenuCurrent
|
||||
description: Reports whether the given page object matches the page object associated with one of the child menu entries under the given menu entry in the given menu.
|
||||
description: Reports whether the given Page object matches the Page object associated with one of the child menu entries under the given menu entry in the given menu.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -11,7 +11,7 @@ action:
|
||||
aliases: [/functions/hasmenucurrent]
|
||||
---
|
||||
|
||||
If the page object associated with the menu entry is a section, this method also returns `true` for any descendant of that section.
|
||||
If the `Page` object associated with the menu entry is a section, this method also returns `true` for any descendant of that section.
|
||||
|
||||
```go-html-template
|
||||
{{ $currentPage := . }}
|
||||
@@ -28,4 +28,4 @@ If the page object associated with the menu entry is a section, this method also
|
||||
|
||||
See [menu templates] for a complete example.
|
||||
|
||||
[menu templates]: /templates/menu-templates/#example
|
||||
[menu templates]: /templates/menu/#example
|
||||
|
||||
@@ -17,7 +17,7 @@ action:
|
||||
toc: true
|
||||
---
|
||||
|
||||
The `InSection` method on a page object reports whether the given page is in the given section. Note that the method returns `true` when comparing a page to a sibling.
|
||||
The `InSection` method on a `Page` object reports whether the given page is in the given section. Note that the method returns `true` when comparing a page to a sibling.
|
||||
|
||||
{{% include "methods/page/_common/definition-of-section.md" %}}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: IsMenuCurrent
|
||||
description: Reports whether the given page object matches the page object associated with the given menu entry in the given menu.
|
||||
description: Reports whether the given Page object matches the Page object associated with the given menu entry in the given menu.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -26,4 +26,4 @@ aliases: [/functions/ismenucurrent]
|
||||
|
||||
See [menu templates] for a complete example.
|
||||
|
||||
[menu templates]: /templates/menu-templates/#example
|
||||
[menu templates]: /templates/menu/#example
|
||||
|
||||
@@ -22,7 +22,12 @@ There is also a `Paginator` method on `Page` objects, but it can neither filter
|
||||
The `Paginate` method is more flexible.
|
||||
{{% /note %}}
|
||||
|
||||
You can invoke pagination on `home`, `section`, `taxonomy`, and `term` pages.
|
||||
You can invoke pagination on the [home template], [section templates], [taxonomy templates], and [term templates].
|
||||
|
||||
[home template]: /templates/types/#home
|
||||
[section templates]: /templates/types/#section
|
||||
[taxonomy templates]: /templates/types/#taxonomy
|
||||
[term templates]: /templates/types/#term
|
||||
|
||||
{{< code file=layouts/_default/list.html >}}
|
||||
{{ $pages := where .Site.RegularPages "Section" "articles" }}
|
||||
@@ -44,6 +49,3 @@ In the example above, we:
|
||||
{{% note %}}
|
||||
Please note that the results of pagination are cached. Once you have invoked either the `Paginator` or `Paginate` method, the paginated collection is immutable. Additional invocations of these methods will have no effect.
|
||||
{{% /note %}}
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
[pagination]: /templates/pagination/
|
||||
|
||||
@@ -16,7 +16,13 @@ The number of elements on each pager is determined by your [site configuration].
|
||||
|
||||
[site configuration]: /getting-started/configuration/#pagination
|
||||
|
||||
You can invoke pagination on `home`, `section`, `taxonomy`, and `term` pages. Each of these receive a collection of regular pages in [context]. When you invoke the `Paginator` method, it paginates the page collection received in context.
|
||||
You can invoke pagination on the [home template], [section templates], [taxonomy templates], and [term templates]. Each of these receives a collection of regular pages in [context]. When you invoke the `Paginator` method, it paginates the page collection received in context.
|
||||
|
||||
[home template]: /templates/types/#home
|
||||
[section templates]: /templates/types/#section
|
||||
[taxonomy templates]: /templates/types/#taxonomy
|
||||
[term templates]: /templates/types/#term
|
||||
[context]: /getting-started/glossary/#context
|
||||
|
||||
{{< code file=layouts/_default/list.html >}}
|
||||
{{ range .Paginator.Pages }}
|
||||
@@ -38,6 +44,3 @@ The [`Paginate`] method is more flexible, and strongly recommended.
|
||||
{{% note %}}
|
||||
Please note that the results of pagination are cached. Once you have invoked either the `Paginator` or `Paginate` method, the paginated collection is immutable. Additional invocations of these methods will have no effect.
|
||||
{{% /note %}}
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
[pagination]: /templates/pagination/
|
||||
|
||||
@@ -70,6 +70,6 @@ layouts/_default/li.html
|
||||
|
||||
See [content views] for more examples.
|
||||
|
||||
[content views]: /templates/views/
|
||||
[content views]: /templates/content-view/
|
||||
[`partial`]: /functions/partials/include/
|
||||
[content type]: /getting-started/glossary/#content-type
|
||||
|
||||
@@ -74,4 +74,4 @@ And this simplistic sitemap template:
|
||||
|
||||
The change frequency will be `hourly` for the news page, and `monthly` for other pages.
|
||||
|
||||
[sitemap templates]: /templates/sitemap-template/
|
||||
[sitemap templates]: /templates/sitemap/
|
||||
|
||||
@@ -7,6 +7,7 @@ keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: methods
|
||||
aliases: [/variables/page/]
|
||||
---
|
||||
|
||||
Use these methods with a Page object.
|
||||
|
||||
@@ -36,7 +36,7 @@ content/
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
This home page template:
|
||||
This home template:
|
||||
|
||||
```go-html-template
|
||||
{{ with .Site.GetPage "/works/paintings" }}
|
||||
@@ -96,7 +96,7 @@ content/
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
In the home page template, use the `GetPage` method on a `Site` object to render all the images in the headless [page bundle]:
|
||||
In the home template, use the `GetPage` method on a `Site` object to render all the images in the headless [page bundle]:
|
||||
|
||||
```go-html-template
|
||||
{{ with .Site.GetPage "/headless" }}
|
||||
|
||||
@@ -46,7 +46,7 @@ Template:
|
||||
|
||||
When creating a theme, instead of hardcoding section names when listing the most relevant pages on the front page, instruct site authors to set `params.mainSections` in their site configuration.
|
||||
|
||||
Then your home page template can do something like this:
|
||||
Then your home template can do something like this:
|
||||
|
||||
```go-html-template
|
||||
{{ range where .Site.RegularPages "Section" "in" .Site.MainSections }}
|
||||
|
||||
@@ -88,7 +88,7 @@ You will typically render a menu using a partial template. As the active menu en
|
||||
|
||||
The example above is simplistic. Please see the [menu templates] section for more information.
|
||||
|
||||
[menu templates]: /templates/menu-templates/
|
||||
[menu templates]: /templates/menu/
|
||||
|
||||
[`partial`]: /functions/partials/include/
|
||||
[`partialCached`]: /functions/partials/includecached/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Taxonomies
|
||||
description: Returns a data structure containing the site's taxonomy objects, the terms within each taxonomy object, and the pages to which the terms are assigned.
|
||||
description: Returns a data structure containing the site's Taxonomy objects, the terms within each Taxonomy object, and the pages to which the terms are assigned.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -9,6 +9,13 @@ action:
|
||||
signatures: [SITE.Taxonomies]
|
||||
---
|
||||
|
||||
<!-- TODO
|
||||
Show template example: GetTerms
|
||||
|
||||
|
||||
|
||||
-->
|
||||
|
||||
Conceptually, the `Taxonomies` method on a `Site` object returns a data structure such as:
|
||||
|
||||
{{< code-toggle >}}
|
||||
@@ -97,3 +104,82 @@ Please see the [taxonomies] section for a complete explanation and examples.
|
||||
|
||||
[taxonomies]: /content-management/taxonomies/
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
|
||||
### List content with the same taxonomy term
|
||||
|
||||
If you are using a taxonomy for something like a series of posts, you can list individual pages associated with the same term. For example:
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Taxonomies.series.golang }}
|
||||
<li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
### List all content in a given taxonomy
|
||||
|
||||
This would be very useful in a sidebar as “featured content”. You could even have different sections of “featured content” by assigning different terms to the content.
|
||||
|
||||
```go-html-template
|
||||
<section id="menu">
|
||||
<ul>
|
||||
{{ range $term, $taxonomy := .Site.Taxonomies.featured }}
|
||||
<li>{{ $term }}</li>
|
||||
<ul>
|
||||
{{ range $taxonomy.Pages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</section>
|
||||
```
|
||||
|
||||
### Render a site's taxonomies
|
||||
|
||||
The following example displays all terms in a site's tags taxonomy:
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Taxonomies.tags }}
|
||||
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
|
||||
|
||||
{{< code file=layouts/partials/all-taxonomies.html >}}
|
||||
{{ with .Site.Taxonomies }}
|
||||
{{ $numberOfTerms := 0 }}
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ $numberOfTerms = len . | add $numberOfTerms }}
|
||||
{{ end }}
|
||||
|
||||
{{ if gt $numberOfTerms 0 }}
|
||||
<ul>
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ with $terms }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $term, $weightedPages := . }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $weightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
@@ -7,6 +7,7 @@ keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: methods
|
||||
aliases: [/variables/site/]
|
||||
---
|
||||
|
||||
Use these methods with Site objects. A multilingual project will have two or more sites, one for each language.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Before we can use a `Taxonomy` method, we need to capture a `Taxonomy` object.
|
||||
|
||||
## Capture a taxonomy object
|
||||
## Capture a Taxonomy object
|
||||
|
||||
Consider this site configuration:
|
||||
|
||||
@@ -26,13 +26,13 @@ content/
|
||||
└── _index.md
|
||||
```
|
||||
|
||||
To capture the "genres" taxonomy object from within any template, use the [`Taxonomies`] method on a `Site` object.
|
||||
To capture the "genres" `Taxonomy` object from within any template, use the [`Taxonomies`] method on a `Site` object.
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomyObject := .Site.Taxonomies.genres }}
|
||||
```
|
||||
|
||||
To capture the "genres" taxonomy object when rendering its page with a taxonomy template, use the [`Terms`] method on the page's [`Data`] object:
|
||||
To capture the "genres" `Taxonomy` object when rendering its page with a taxonomy template, use the [`Terms`] method on the page's [`Data`] object:
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ $taxonomyObject := .Data.Terms }}
|
||||
|
||||
@@ -35,6 +35,19 @@ Use the [`where`] function to filter page collections.
|
||||
|
||||
## Sort
|
||||
|
||||
By default, Hugo sorts page collections by:
|
||||
|
||||
1. [Weight]
|
||||
2. [Date] in descending order
|
||||
3. [LinkTitle] falling back to [Title]
|
||||
4. [Filename] if the page is backed by a file
|
||||
|
||||
[Date]: /methods/page/date/
|
||||
[Weight]: /methods/page/weight/
|
||||
[LinkTitle]: /methods/page/linktitle/
|
||||
[Title]: /methods/page/title/
|
||||
[Filename]: /methods/page/file/#filename
|
||||
|
||||
Use these methods to sort page collections.
|
||||
|
||||
{{< list-pages-in-section path=/methods/pages filter=methods_pages_sort filterType=include titlePrefix=. omitElementIDs=true titlePrefix=PAGES. >}}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
title: Custom 404 page
|
||||
linkTitle: 404 template
|
||||
linkTitle: 404 templates
|
||||
description: Create a template to render a 404 error page.
|
||||
categories: [templates]
|
||||
keywords: ['404',page not found]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 220
|
||||
weight: 220
|
||||
weight: 160
|
||||
weight: 160
|
||||
---
|
||||
|
||||
To render a 404 error page in the root of your site, create a 404 template in the root of the layouts directory. For example:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
cascade:
|
||||
_build:
|
||||
list: never
|
||||
publishResources: false
|
||||
render: never
|
||||
---
|
||||
|
||||
<!--
|
||||
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
|
||||
|
||||
Include the rendered content using the "include" shortcode.
|
||||
-->
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
# Do not remove front matter.
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
The [page collections quick reference guide] describes methods and functions to filter, sort, and group page collections.
|
||||
|
||||
[page collections quick reference guide]: /quick-reference/page-collections/
|
||||
{{% /note %}}
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: Base templates and blocks
|
||||
description: The base and block constructs allow you to define the outer shell of your master templates (i.e., the chrome of the page).
|
||||
title: Base templates
|
||||
description: The base and block construct allows you to define the outer shell of your master templates (i.e., the chrome of the page).
|
||||
categories: [templates,fundamentals]
|
||||
keywords: [blocks,base]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 40
|
||||
weight: 40
|
||||
weight: 50
|
||||
weight: 50
|
||||
toc: true
|
||||
aliases: [/templates/blocks/,/templates/base-templates-and-blocks/]
|
||||
---
|
||||
@@ -50,7 +50,7 @@ The following defines a simple base template at `_default/baseof.html`. As a def
|
||||
|
||||
## Override the base template
|
||||
|
||||
From the above base template, you can define a [default list template][hugolists]. The default list template will inherit all of the code defined above and can then implement its own `"main"` block from:
|
||||
The default list template will inherit all of the code defined above and can then implement its own `"main"` block from:
|
||||
|
||||
{{< code file=layouts/_default/list.html >}}
|
||||
{{ define "main" }}
|
||||
@@ -78,7 +78,7 @@ Code that you put outside the block definitions *can* break your layout. This ev
|
||||
[See this thread from the Hugo discussion forums.](https://discourse.gohugo.io/t/baseof-html-block-templates-and-list-types-results-in-empty-pages/5612/6)
|
||||
{{% /note %}}
|
||||
|
||||
The following shows how you can override both the `"main"` and `"title"` block areas from the base template with code unique to your [default single page template][singletemplate]:
|
||||
The following shows how you can override both the `"main"` and `"title"` block areas from the base template with code unique to your default [single template]:
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
{{ define "title" }}
|
||||
@@ -91,7 +91,4 @@ The following shows how you can override both the `"main"` and `"title"` block a
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
[hugolists]: /templates/lists/
|
||||
[lookup]: /templates/lookup-order/
|
||||
[rendering the section]: /templates/section-templates/
|
||||
[singletemplate]: /templates/single-page-templates/
|
||||
[single template]: /templates/types/#single
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
title: Content view templates
|
||||
description: Hugo can render alternative views of your content, useful in list and summary views.
|
||||
categories: [templates]
|
||||
keywords: [views]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 110
|
||||
weight: 110
|
||||
weight: 120
|
||||
weight: 120
|
||||
toc: true
|
||||
aliases: [/templates/views/]
|
||||
---
|
||||
|
||||
These alternative **content views** are especially useful in [list templates][lists].
|
||||
|
||||
The following are common use cases for content views:
|
||||
|
||||
* You want content of every type to be shown on the homepage but only with limited [summary views][summaries].
|
||||
* You only want a bulleted list of your content on a [taxonomy list page][taxonomylists]. Views make this very straightforward by delegating the rendering of each different type of content to the content itself.
|
||||
* You want content of every type to be shown on the home page but only with limited [summary views][summaries].
|
||||
* You only want a bulleted list of your content in a [taxonomy template]. Views make this very straightforward by delegating the rendering of each different type of content to the content itself.
|
||||
|
||||
## Create a content view
|
||||
|
||||
To create a new view, create a template in each of your different content type directories with the view name. The following example contains an "li" view and a "summary" view for the `posts` and `project` content types. As you can see, these sit next to the [single content view][single] template, `single.html`. You can even provide a specific view for a given type and continue to use the `_default/single.html` for the primary view.
|
||||
To create a new view, create a template in each of your different content type directories with the view name. The following example contains an "li" view and a "summary" view for the `posts` and `project` content types. As you can see, these sit next to the [single template], `single.html`. You can even provide a specific view for a given type and continue to use the `_default/single.html` for the primary view.
|
||||
|
||||
```txt
|
||||
▾ layouts/
|
||||
@@ -30,33 +29,23 @@ To create a new view, create a template in each of your different content type d
|
||||
summary.html
|
||||
▾ project/
|
||||
li.html
|
||||
single.html
|
||||
summary.html
|
||||
```
|
||||
|
||||
Hugo also has support for a default content view template to be used in the event that a specific content view template has not been provided for that type. Content views can also be defined in the `_default` directory and will work the same as list and single templates who eventually trickle down to the `_default` directory as a matter of the lookup order.
|
||||
|
||||
```txt
|
||||
▾ layouts/
|
||||
▾ _default/
|
||||
li.html
|
||||
single.html
|
||||
single.htm]
|
||||
summary.html
|
||||
```
|
||||
|
||||
## Which template will be rendered?
|
||||
|
||||
The following is the [lookup order] for content views:
|
||||
The following is the lookup order for content views ordered by specificity.
|
||||
|
||||
1. `/layouts/<TYPE>/<VIEW>.html`
|
||||
2. `/layouts/_default/<VIEW>.html`
|
||||
3. `/themes/<THEME>/layouts/<TYPE>/<VIEW>.html`
|
||||
4. `/themes/<THEME>/layouts/_default/<VIEW>.html`
|
||||
1. `/layouts/<SECTION>/<VIEW>.html`
|
||||
1. `/layouts/_default/<VIEW>.html`
|
||||
1. `/themes/<THEME>/layouts/<TYPE>/<VIEW>.html`
|
||||
1. `/themes/<THEME>/layouts/<SECTION>/<VIEW>.html`
|
||||
1. `/themes/<THEME>/layouts/_default/<VIEW>.html`
|
||||
|
||||
## Example: content view inside a list
|
||||
|
||||
The following example demonstrates how to use content views inside your [list templates][lists].
|
||||
|
||||
### `list.html`
|
||||
|
||||
In this example, `.Render` is passed into the template to call the [render function][render]. `.Render` is a special function that instructs content to render itself with the view template provided as the first argument. In this case, the template is going to render the `summary.html` view that follows:
|
||||
@@ -74,7 +63,7 @@ In this example, `.Render` is passed into the template to call the [render funct
|
||||
|
||||
### `summary.html`
|
||||
|
||||
Hugo passes the page object to the following `summary.html` view template.
|
||||
Hugo passes the `Page` object to the following `summary.html` view template.
|
||||
|
||||
{{< code file=layouts/_default/summary.html >}}
|
||||
<article class="post">
|
||||
@@ -100,8 +89,7 @@ Continuing on the previous example, we can change our render function to use a s
|
||||
</li>
|
||||
{{< /code >}}
|
||||
|
||||
[lists]: /templates/lists/
|
||||
[render]: /methods/page/render/
|
||||
[single]: /templates/single-page-templates/
|
||||
[single template]: /templates/types/#single
|
||||
[summaries]: /content-management/summaries/
|
||||
[taxonomylists]: /templates/taxonomy-templates/
|
||||
[taxonomy template]: /templates/types/#taxonomy
|
||||
@@ -2,12 +2,12 @@
|
||||
title: Embedded templates
|
||||
description: Hugo provides embedded templates for common use cases.
|
||||
categories: [templates]
|
||||
keywords: [internal, analytics,]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 190
|
||||
weight: 190
|
||||
weight: 200
|
||||
weight: 200
|
||||
toc: true
|
||||
aliases: [/templates/internal]
|
||||
---
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
title: Home templates
|
||||
description: The home page of a website is often formatted differently than the other pages. For this reason, Hugo makes it easy for you to define your new site's home page as a unique template.
|
||||
categories: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 60
|
||||
weight: 60
|
||||
toc: true
|
||||
aliases: [/layout/homepage/,/templates/homepage-template/,/templates/homepage/]
|
||||
---
|
||||
|
||||
The home template is the *only* required template for building a site and therefore useful when bootstrapping a new site and template. It is also the only required template if you are developing a single-page website.
|
||||
|
||||
|
||||
{{< youtube ut1xtRZ1QOA >}}
|
||||
|
||||
## Home template lookup order
|
||||
|
||||
See [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
## Add content and front matter to the home page
|
||||
|
||||
The home page accepts content and front matter from an `_index.md` file. This file should live at the root of your `content` folder (i.e., `content/_index.md`). You can then add body copy and metadata to your home page the way you would any other content file.
|
||||
|
||||
See the home template below or [Content Organization][contentorg] for more information on the role of `_index.md` in adding content and front matter to list pages.
|
||||
|
||||
## Example home template
|
||||
|
||||
{{< code file=layouts/_default/home.html >}}
|
||||
{{ define "main" }}
|
||||
<main aria-role="main">
|
||||
<header class="home-page-header">
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span class="subtitle">{{ . }}</span>
|
||||
{{ end }}
|
||||
</header>
|
||||
<div class="home-page-content">
|
||||
<!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<div>
|
||||
{{ range first 10 .Site.RegularPages }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
[contentorg]: /content-management/organization/
|
||||
[lookup]: /templates/lookup-order/
|
||||
@@ -1,56 +0,0 @@
|
||||
---
|
||||
title: Homepage template
|
||||
description: The homepage of a website is often formatted differently than the other pages. For this reason, Hugo makes it easy for you to define your new site's homepage as a unique template.
|
||||
categories: [templates]
|
||||
keywords: [homepage]
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 70
|
||||
weight: 70
|
||||
toc: true
|
||||
aliases: [/layout/homepage/,/templates/homepage-template/]
|
||||
---
|
||||
|
||||
The homepage template is the *only* required template for building a site and therefore useful when bootstrapping a new site and template. It is also the only required template if you are developing a single-page website.
|
||||
|
||||
|
||||
{{< youtube ut1xtRZ1QOA >}}
|
||||
|
||||
## Homepage template lookup order
|
||||
|
||||
See [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
## Add content and front matter to the homepage
|
||||
|
||||
The homepage, similar to other [list pages in Hugo][lists], accepts content and front matter from an `_index.md` file. This file should live at the root of your `content` folder (i.e., `content/_index.md`). You can then add body copy and metadata to your homepage the way you would any other content file.
|
||||
|
||||
See the homepage template below or [Content Organization][contentorg] for more information on the role of `_index.md` in adding content and front matter to list pages.
|
||||
|
||||
## Example homepage template
|
||||
|
||||
{{< code file=layouts/index.html >}}
|
||||
{{ define "main" }}
|
||||
<main aria-role="main">
|
||||
<header class="homepage-header">
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span class="subtitle">{{ . }}</span>
|
||||
{{ end }}
|
||||
</header>
|
||||
<div class="homepage-content">
|
||||
<!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<div>
|
||||
{{ range first 10 .Site.RegularPages }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
[contentorg]: /content-management/organization/
|
||||
[lists]: /templates/lists/
|
||||
[lookup]: /templates/lookup-order/
|
||||
@@ -403,7 +403,7 @@ Use the [`template`] function to include one or more of Hugo's [embedded templat
|
||||
|
||||
Use the [`partial`] or [`partialCached`] function to include one or more [partial templates]:
|
||||
|
||||
[partial templates]: /templates/partials
|
||||
[partial templates]: /templates/partial
|
||||
|
||||
```go-html-template
|
||||
{{ partial "breadcrumbs.html" . }}
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
---
|
||||
title: Lists of content in Hugo
|
||||
linkTitle: List templates
|
||||
description: Lists have a specific meaning and usage in Hugo when it comes to rendering your site homepage, section page, taxonomy list, or taxonomy terms list.
|
||||
categories: [templates]
|
||||
keywords: [lists,sections,rss,taxonomies,terms]
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 60
|
||||
weight: 60
|
||||
toc: true
|
||||
aliases: [/templates/list/,/layout/indexes/]
|
||||
---
|
||||
|
||||
## What is a list page template?
|
||||
|
||||
{{< youtube 8b2YTSMdMps >}}
|
||||
|
||||
A list page template is a template used to render multiple pieces of content in a single HTML page. The exception to this rule is the homepage, which is still a list but has its own [dedicated template][homepage].
|
||||
|
||||
Hugo uses the term *list* in its truest sense; i.e. a sequential arrangement of material, especially in alphabetical or numerical order. Hugo uses list templates on any output HTML page where content is traditionally listed:
|
||||
|
||||
* [Home page](/templates/homepage)
|
||||
* [Section pages](/templates/section-templates)
|
||||
* [Taxonomy pages](/templates/taxonomy-templates)
|
||||
* [Taxonomy term pages](/templates/taxonomy-templates)
|
||||
* [RSS feeds](/templates/rss)
|
||||
* [Sitemaps](/templates/sitemap-template)
|
||||
|
||||
For template lookup order, see [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
The idea of a list page comes from the [hierarchical mental model of the web][mentalmodel] and is best demonstrated visually:
|
||||
|
||||
[](site-hierarchy.svg)
|
||||
|
||||
## Add content and front matter to list pages
|
||||
|
||||
Add content and front matter to list pages by creating an _index.md file for `home`, `section`, `taxonomy`, and `term` pages.
|
||||
|
||||
The following is an example of a typical Hugo project directory's content:
|
||||
|
||||
```txt
|
||||
.
|
||||
...
|
||||
├── content
|
||||
| ├── posts
|
||||
| | ├── _index.md
|
||||
| | ├── post-01.md
|
||||
| | └── post-02.md
|
||||
| └── quote
|
||||
| | ├── quote-01.md
|
||||
| | └── quote-02.md
|
||||
...
|
||||
```
|
||||
|
||||
Using the above example, let's assume you have the following in `content/posts/_index.md`:
|
||||
|
||||
{{< code file=content/posts/_index.md >}}
|
||||
---
|
||||
title: My Go Journey
|
||||
date: 2017-03-23
|
||||
publishdate: 2017-03-24
|
||||
---
|
||||
|
||||
I decided to start learning Go in March 2017.
|
||||
|
||||
Follow my journey through this new blog.
|
||||
{{< /code >}}
|
||||
|
||||
You can now access this `_index.md`'s' content in your list template:
|
||||
|
||||
{{< code file=layouts/_default/list.html >}}
|
||||
{{ define "main" }}
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{ .Title }}</h1>
|
||||
</header>
|
||||
<!-- "{{ .Content }}" pulls from the Markdown content of the corresponding _index.md -->
|
||||
{{ .Content }}
|
||||
</article>
|
||||
<ul>
|
||||
<!-- Ranges through content/posts/*.md -->
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .RelPermalink }}">{{ .Date.Format "2006-01-02" }} | {{ .LinkTitle }}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
This above will output the following HTML:
|
||||
|
||||
{{< code file=example.com/posts/index.html >}}
|
||||
<!--top of your baseof code-->
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>My Go Journey</h1>
|
||||
</header>
|
||||
<p>I decided to start learning Go in March 2017.</p>
|
||||
<p>Follow my journey through this new blog.</p>
|
||||
</article>
|
||||
<ul>
|
||||
<li><a href="/posts/post-01/">Post 1</a></li>
|
||||
<li><a href="/posts/post-02/">Post 2</a></li>
|
||||
</ul>
|
||||
</main>
|
||||
<!--bottom of your baseof-->
|
||||
{{< /code >}}
|
||||
|
||||
### List pages without `_index.md`
|
||||
|
||||
You do *not* have to create an `_index.md` file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an `_index.md` within the respective content section when rendering a list template, the page will be created but with no `{{ .Content }}` and only the default values for `.Title` etc.
|
||||
|
||||
Using this same `layouts/_default/list.html` template and applying it to the `quotes` section above will render the following output. Note that `quotes` does not have an `_index.md` file to pull from:
|
||||
|
||||
{{< code file=example.com/quote/index.html >}}
|
||||
<!--baseof-->
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<!-- Hugo assumes that .Title is the name of the section since there is no _index.md content file from which to pull a "title:" field -->
|
||||
<h1>Quotes</h1>
|
||||
</header>
|
||||
</article>
|
||||
<ul>
|
||||
<li><a href="https://example.org/quote/quotes-01/">Quote 1</a></li>
|
||||
<li><a href="https://example.org/quote/quotes-02/">Quote 2</a></li>
|
||||
</ul>
|
||||
</main>
|
||||
<!--baseof-->
|
||||
{{< /code >}}
|
||||
|
||||
{{% note %}}
|
||||
By default, Hugo capitalizes and pluralizes automatic list titles including section, taxonomy, and term pages. You can disable these transformations by setting [`capitalizeListTitles`] and [`pluralizeListTitles`] in your site configuration.
|
||||
|
||||
You can change the capitalization style in your site configuration to one of `ap`, `chicago`, `go`, `firstupper`, or `none`. See [details].
|
||||
|
||||
[`capitalizeListTitles`]: /getting-started/configuration/#capitalizelisttitles
|
||||
[`pluralizeListTitles`]: /getting-started/configuration/#pluralizelisttitles
|
||||
[details]: /getting-started/configuration/#configure-title-case
|
||||
{{% /note %}}
|
||||
|
||||
## Example list templates
|
||||
|
||||
### Section template
|
||||
|
||||
This list template has been modified slightly from a template originally used in [spf13.com](https://spf13.com/). It makes use of [partial templates][partials] for the chrome of the rendered page rather than using a [base template][base]. The examples that follow also use the [content view templates][views] `li.html` or `summary.html`.
|
||||
|
||||
{{< code file=layouts/section/posts.html >}}
|
||||
{{ partial "header.html" . }}
|
||||
{{ partial "subheader.html" . }}
|
||||
<main>
|
||||
<div>
|
||||
<h1>{{ .Title }}</h1>
|
||||
<ul>
|
||||
<!-- Renders the li.html content view for each content/posts/*.md -->
|
||||
{{ range .Pages }}
|
||||
{{ .Render "li" }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
</main>
|
||||
{{ partial "footer.html" . }}
|
||||
{{< /code >}}
|
||||
|
||||
### Taxonomy template
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<main>
|
||||
<div>
|
||||
<h1>{{ .Title }}</h1>
|
||||
<!-- ranges through each of the content files associated with a particular taxonomy term and renders the summary.html content view -->
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
## Sort content
|
||||
|
||||
By default, Hugo sorts page collections by:
|
||||
|
||||
1. Page [weight]
|
||||
2. Page [date] (descending)
|
||||
3. Page [linkTitle], falling back to page [title]
|
||||
4. Page file path if the page is backed by a file
|
||||
|
||||
[date]: /methods/page/date/
|
||||
[weight]: /methods/page/weight/
|
||||
[linkTitle]: /methods/page/linktitle/
|
||||
[title]: /methods/page/title/
|
||||
|
||||
Change the sort order using any of the methods below.
|
||||
|
||||
{{< list-pages-in-section path=/methods/pages filter=methods_pages_sort filterType=include titlePrefix=. omitElementIDs=true >}}
|
||||
|
||||
## Group content
|
||||
|
||||
Group your content by field, parameter, or date using any of the methods below.
|
||||
|
||||
{{< list-pages-in-section path=/methods/pages filter=methods_pages_group filterType=include titlePrefix=. omitElementIDs=true >}}
|
||||
|
||||
## Filtering and limiting lists
|
||||
|
||||
Sometimes you only want to list a subset of the available content. A
|
||||
common is to only display posts from [main sections]
|
||||
on the blog's homepage.
|
||||
|
||||
See the documentation on [`where`] and
|
||||
[`first`] for further details.
|
||||
|
||||
[base]: /templates/base/
|
||||
[bepsays]: https://bepsays.com/en/2016/12/19/hugo-018/
|
||||
[directorystructure]: /getting-started/directory-structure/
|
||||
[`Format` function]: /methods/time/format/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[getpage]: /methods/page/getpage/
|
||||
[homepage]: /templates/homepage/
|
||||
[mentalmodel]: https://webstyleguide.com/wsg3/3-information-architecture/3-site-structure.html
|
||||
[partials]: /templates/partials/
|
||||
[RSS 2.0]: https://cyber.harvard.edu/rss/rss.html
|
||||
[rss]: /templates/rss/
|
||||
[sections]: /content-management/sections/
|
||||
[sectiontemps]: /templates/section-templates/
|
||||
[taxlists]: /templates/taxonomy-templates/#taxonomy-templates
|
||||
[taxterms]: /templates/taxonomy-templates/#term-templates
|
||||
[taxvars]: /methods/taxonomy/
|
||||
[views]: /templates/views/
|
||||
[`where`]: /functions/collections/where/
|
||||
[`first`]: /functions/collections/first/
|
||||
[main sections]: /methods/site/mainsections/
|
||||
[`time.Format`]: /functions/time/format/
|
||||
@@ -1,13 +1,14 @@
|
||||
---
|
||||
title: Template lookup order
|
||||
linkTitle: Lookup order
|
||||
description: Hugo uses the rules below to select a template for a given page, starting from the most specific.
|
||||
categories: [templates,fundamentals]
|
||||
keywords: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 30
|
||||
weight: 30
|
||||
weight: 40
|
||||
weight: 40
|
||||
toc: true
|
||||
---
|
||||
|
||||
@@ -99,23 +100,29 @@ layouts/
|
||||
└── single.html <-- renders about.md
|
||||
```
|
||||
|
||||
## Home page
|
||||
## 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 pages
|
||||
## 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 pages
|
||||
## Section templates
|
||||
|
||||
A section page is a list of pages within a given section.
|
||||
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 pages
|
||||
## Taxonomy templates
|
||||
|
||||
A taxonomy page is a list of terms within a given taxonomy. The examples below assume the following site configuration:
|
||||
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]
|
||||
@@ -124,9 +131,11 @@ category = 'categories'
|
||||
|
||||
{{< datatable-filtered "output" "layouts" "Kind == taxonomy" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
|
||||
|
||||
## Term pages
|
||||
## Term templates
|
||||
|
||||
A term page is a list of pages associated with a given term. The examples below assume the following site configuration:
|
||||
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]
|
||||
@@ -134,3 +143,16 @@ 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" >}}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
---
|
||||
title: Menu templates
|
||||
title: Menus
|
||||
description: Create templates to render one or more menus.
|
||||
categories: [templates]
|
||||
keywords: [lists,sections,menus]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
identifier: templates-menu
|
||||
parent: templates
|
||||
weight: 140
|
||||
weight: 140
|
||||
weight: 180
|
||||
weight: 180
|
||||
toc: true
|
||||
aliases: [/templates/menus/]
|
||||
aliases: [/templates/menus/,/templates/menu-templates/]
|
||||
---
|
||||
|
||||
## Overview
|
||||
@@ -2,7 +2,7 @@
|
||||
title: Custom output formats
|
||||
description: Hugo can output content in multiple formats, including calendar events, e-book formats, Google AMP, and JSON search indexes, or any custom text format.
|
||||
categories: [templates,fundamentals]
|
||||
keywords: ["amp", "outputs", "rss"]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
@@ -79,7 +79,7 @@ isPlainText = true
|
||||
protocol = "bep://"
|
||||
{{</ code-toggle >}}
|
||||
|
||||
The above example is fictional, but if used for the homepage on a site with `baseURL` `https://example.org`, it will produce a plain text homepage with the URL `bep://example.org/myindex.enr`.
|
||||
The above example is fictional, but if used for the home page on a site with `baseURL` `https://example.org`, it will produce a plain text home page with the URL `bep://example.org/myindex.enr`.
|
||||
|
||||
### Configure output formats
|
||||
|
||||
@@ -163,7 +163,7 @@ Example from site configuration file:
|
||||
Note that in the above examples, the _output formats_ for `section`,
|
||||
`taxonomy` and `term` will stay at their default value `['html','rss']`.
|
||||
|
||||
* The `outputs` definition is per page [`Kind`][page_kinds].
|
||||
* The `outputs` definition is per page [`Kind`].
|
||||
* The names (e.g. `html`, `amp`) must match the `name` of a defined output format, and can be overridden per page in front matter.
|
||||
|
||||
The following is an example of front matter in a content file that defines output formats for the rendered `Page`:
|
||||
@@ -242,9 +242,7 @@ The partial below is a plain text template . The output format is `csv`, and sin
|
||||
{{ partial "mytextpartial.csv" . }}
|
||||
```
|
||||
|
||||
[base]: /templates/base/
|
||||
[site configuration]: /getting-started/configuration/
|
||||
[lookup order]: /templates/lookup-order/
|
||||
[media type]: https://en.wikipedia.org/wiki/Media_type
|
||||
[partials]: /templates/partials/
|
||||
[`kind`]: /methods/page/kind/
|
||||
|
||||
@@ -6,8 +6,8 @@ keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 180
|
||||
weight: 180
|
||||
weight: 190
|
||||
weight: 190
|
||||
toc: true
|
||||
aliases: [/extras/pagination,/doc/pagination/]
|
||||
---
|
||||
@@ -27,7 +27,7 @@ The most common templating mistake related to pagination is invoking pagination
|
||||
## Terminology
|
||||
|
||||
paginate
|
||||
: To split a list page into two or more subsets.
|
||||
: To split a [list page] into two or more subsets.
|
||||
|
||||
pagination
|
||||
: The process of paginating a list page.
|
||||
@@ -38,6 +38,8 @@ pager
|
||||
paginator
|
||||
: A collection of pagers.
|
||||
|
||||
[list page]: /getting-started/glossary/#list-page
|
||||
|
||||
## Configuration
|
||||
|
||||
Control pagination behavior in your site configuration. These are the default settings:
|
||||
@@ -150,7 +152,9 @@ When paginating conditionally, do not use the `compare.Conditional` function due
|
||||
|
||||
## Grouping
|
||||
|
||||
Use pagination with any of the grouping methods. For example:
|
||||
Use pagination with any of the [grouping methods]. For example:
|
||||
|
||||
[grouping methods]: /quick-reference/page-collections/#group
|
||||
|
||||
```go-html-template
|
||||
{{ $pages := where site.RegularPages "Type" "posts" }}
|
||||
|
||||
@@ -2,27 +2,18 @@
|
||||
title: Partial templates
|
||||
description: Partials are smaller, context-aware components in your list and page templates that can be used economically to keep your templating DRY.
|
||||
categories: [templates]
|
||||
keywords: [lists,sections,partials]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 120
|
||||
weight: 120
|
||||
weight: 110
|
||||
weight: 110
|
||||
toc: true
|
||||
aliases: [/templates/partial/,/layout/chrome/,/extras/analytics/]
|
||||
aliases: [/templates/partials/,/layout/chrome/]
|
||||
---
|
||||
|
||||
{{< youtube pjS4pOLyB7c >}}
|
||||
|
||||
## Partial template lookup order
|
||||
|
||||
Partial templates---like [single page templates][singletemps] and [list page templates][listtemps]---have a specific [lookup order]. However, partials are simpler in that Hugo will only check in two places:
|
||||
|
||||
1. `layouts/partials/<PARTIALNAME>.html`
|
||||
2. `themes/<THEME>/layouts/partials/<PARTIALNAME>.html`
|
||||
|
||||
This allows a theme's end user to copy a partial's contents into a file of the same name for [further customization][customize].
|
||||
|
||||
## Use partials in your templates
|
||||
|
||||
All partials for your Hugo project are located in a single `layouts/partials` directory. For better organization, you can create multiple subdirectories within `partials` as well:
|
||||
@@ -50,7 +41,7 @@ All partials are called within your templates using the following pattern:
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
One of the most common mistakes with new Hugo users is failing to pass a context to the partial call. In the pattern above, note how "the dot" (`.`) is required as the second argument to give the partial context. You can read more about "the dot" in the [Hugo templating introduction](/templates/introduction/).
|
||||
One of the most common mistakes with new Hugo users is failing to pass a context to the partial call. In the pattern above, note how "the dot" (`.`) is required as the second argument to give the partial context. You can read more about "the dot" in the [Hugo templating introduction](/templates/introduction/#context).
|
||||
{{% /note %}}
|
||||
|
||||
{{% note %}}
|
||||
@@ -175,8 +166,6 @@ The following `footer.html` partial template is used for [spf13.com](https://spf
|
||||
|
||||
[context]: /templates/introduction/
|
||||
[customize]: /hugo-modules/theme-components/
|
||||
[listtemps]: /templates/lists/
|
||||
[lookup order]: /templates/lookup-order/
|
||||
[partialcached]: /functions/partials/includecached/
|
||||
[singletemps]: /templates/single-page-templates/
|
||||
[themes]: /themes/
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
title: Robots.txt file
|
||||
linkTitle: Robots.txt
|
||||
title: robots.txt template
|
||||
linkTitle: robots.txt templates
|
||||
description: Hugo can generate a customized robots.txt in the same way as any other template.
|
||||
categories: [templates]
|
||||
keywords: [robots,search engines]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 230
|
||||
weight: 230
|
||||
weight: 170
|
||||
weight: 170
|
||||
aliases: [/extras/robots-txt/]
|
||||
---
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
title: RSS templates
|
||||
description: Use the embedded RSS template, or create your own.
|
||||
categories: [templates]
|
||||
keywords: [rss,xml,templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 160
|
||||
weight: 160
|
||||
weight: 150
|
||||
weight: 150
|
||||
toc: true
|
||||
---
|
||||
|
||||
@@ -70,7 +70,7 @@ Hugo will render this to:
|
||||
Override Hugo's [embedded RSS template] by creating one or more of your own, following the naming conventions as shown in the [template lookup order].
|
||||
|
||||
[embedded RSS template]: {{% eturl rss %}}
|
||||
[template lookup order]: #template-lookup-order
|
||||
[template lookup order]: /templates/lookup-order/#rss-templates
|
||||
|
||||
For example, to use different templates for home, section, taxonomy, and term pages:
|
||||
|
||||
@@ -84,9 +84,3 @@ layouts/
|
||||
```
|
||||
|
||||
RSS templates receive the `.Page` and `.Site` objects in context.
|
||||
|
||||
## Template lookup order
|
||||
|
||||
The table below shows the RSS template lookup order for the different page kinds. The first listing shows the lookup order when running with a theme (`demoTheme`).
|
||||
|
||||
{{< datatable-filtered "output" "layouts" "OutputFormat == rss" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
---
|
||||
title: Section page templates
|
||||
linkTitle: Section templates
|
||||
title: Section templates
|
||||
description: Use section templates to list members of a section.
|
||||
categories: [templates]
|
||||
keywords: [lists,sections,templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 80
|
||||
weight: 80
|
||||
toc: true
|
||||
aliases: [/templates/sections/]
|
||||
aliases: [/templates/sections/,/templates/section-templates/]
|
||||
---
|
||||
|
||||
## Add content and front matter to section templates
|
||||
|
||||
To effectively leverage section page templates, you should first understand Hugo's [content organization](/content-management/organization/) and, specifically, the purpose of `_index.md` for adding content and front matter to section and other list pages.
|
||||
To effectively leverage section templates, you should first understand Hugo's [content organization](/content-management/organization/) and, specifically, the purpose of `_index.md` for adding content and front matter to section and other list pages.
|
||||
|
||||
## Section template lookup order
|
||||
|
||||
@@ -82,8 +81,6 @@ Which then returns the following:
|
||||
```
|
||||
|
||||
[contentorg]: /content-management/organization/
|
||||
[getpage]: /methods/page/getpage/
|
||||
[lists]: /templates/lists/
|
||||
[lookup]: /templates/lookup-order/
|
||||
[`where`]: /functions/collections/where/
|
||||
[sections]: /content-management/sections/
|
||||
@@ -3,13 +3,13 @@ title: Create your own shortcodes
|
||||
linkTitle: Shortcode templates
|
||||
description: You can extend Hugo's embedded shortcodes by creating your own using the same templating syntax as that for single and list pages.
|
||||
categories: [templates]
|
||||
keywords: [shortcodes,templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 130
|
||||
weight: 130
|
||||
aliases: [/functions/get]
|
||||
aliases: [/templates/shortcode-templates/]
|
||||
toc: true
|
||||
---
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
---
|
||||
title: Single page templates
|
||||
description: The primary view of content in Hugo is the single view. Hugo will render every Markdown file provided with a corresponding single template.
|
||||
categories: [templates]
|
||||
keywords: [page, templates]
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 50
|
||||
weight: 50
|
||||
toc: true
|
||||
aliases: [/layout/content/]
|
||||
---
|
||||
|
||||
## Single page template lookup order
|
||||
|
||||
See [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
## Example single page templates
|
||||
|
||||
{{< code file=layouts/posts/single.html >}}
|
||||
{{ define "main" }}
|
||||
<section id="main">
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
<div>
|
||||
<article id="content">
|
||||
{{ .Content }}
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<aside id="meta">
|
||||
<div>
|
||||
<section>
|
||||
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
||||
<h5 id="wordcount"> {{ .WordCount }} Words</h5>
|
||||
</section>
|
||||
{{ with .GetTerms "topics" }}
|
||||
<ul id="topics">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ with .GetTerms "tags" }}
|
||||
<ul id="tags">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div>
|
||||
{{ with .PrevInSection }}
|
||||
<a class="previous" href="{{ .RelPermalink }}"> {{ .LinkTitle }}</a>
|
||||
{{ end }}
|
||||
{{ with .NextInSection }}
|
||||
<a class="next" href="{{ .RelPermalink }}"> {{ .LinkTitle }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</aside>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
To easily generate new instances of a content type (e.g., new `.md` files in a section like `project/`) with preconfigured front matter, use [content archetypes][archetypes].
|
||||
|
||||
[archetypes]: /content-management/archetypes/
|
||||
[base templates]: /templates/base/
|
||||
[content type]: /content-management/types/
|
||||
[directory structure]: /getting-started/directory-structure/
|
||||
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
||||
[`.format` function]: /methods/time/format/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[pagetaxonomy]: /templates/taxonomy-templates/#list-terms-assigned-to-a-page
|
||||
[partials]: /templates/partials/
|
||||
[section]: /content-management/sections/
|
||||
[spf13]: https://spf13.com/
|
||||
[`with`]: /functions/go-template/with/
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: Single templates
|
||||
description: Create a single template to render a single page.
|
||||
categories: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 70
|
||||
weight: 70
|
||||
toc: true
|
||||
aliases: [/layout/content/,/templates/single-page-templates/]
|
||||
---
|
||||
|
||||
The single template below inherits the site's shell from the [base template].
|
||||
|
||||
[base template]: /templates/types/
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Review the [template lookup order] to select a template path that provides the desired level of specificity.
|
||||
|
||||
[template lookup order]: /templates/lookup-order/#single-templates
|
||||
|
||||
The single template below inherits the site's shell from the base template, and renders the page title, creation date, content, and a list of associated terms in the "tags" taxonomy.
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
{{ define "main" }}
|
||||
<section>
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Date }}
|
||||
{{ $dateMachine := . | time.Format "2006-01-02T15:04:05-07:00" }}
|
||||
{{ $dateHuman := . | time.Format ":date_long" }}
|
||||
<time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
|
||||
{{ end }}
|
||||
<article>
|
||||
{{ .Content }}
|
||||
</article>
|
||||
<aside>
|
||||
{{ with .GetTerms "tags" }}
|
||||
<div>{{ (index . 0).Parent.LinkTitle }}</div>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</aside>
|
||||
</section>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
@@ -2,14 +2,14 @@
|
||||
title: Sitemap templates
|
||||
description: Hugo provides built-in sitemap templates.
|
||||
categories: [templates]
|
||||
keywords: [sitemap,xml,templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 170
|
||||
weight: 170
|
||||
weight: 140
|
||||
weight: 140
|
||||
toc: true
|
||||
aliases: [/layout/sitemap/,/templates/sitemap/]
|
||||
aliases: [/layout/sitemap/,/templates/sitemap-template/]
|
||||
---
|
||||
|
||||
## Overview
|
||||
@@ -1,285 +0,0 @@
|
||||
---
|
||||
title: Taxonomy templates
|
||||
description: Taxonomy templating includes taxonomy list pages, taxonomy terms pages, and using taxonomies in your single page templates.
|
||||
categories: [templates]
|
||||
keywords: [taxonomies,metadata,front matter,terms,templates]
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 90
|
||||
weight: 90
|
||||
toc: true
|
||||
aliases: [/taxonomies/displaying/,/templates/terms/,/indexes/displaying/,/taxonomies/templates/,/indexes/ordering/, /templates/taxonomies/, /templates/taxonomy/]
|
||||
---
|
||||
|
||||
Hugo includes support for user-defined groupings of content called **taxonomies**. Taxonomies are classifications that demonstrate logical relationships between content. See [Taxonomies under Content Management](/content-management/taxonomies) if you are unfamiliar with how Hugo leverages this powerful feature.
|
||||
|
||||
Hugo provides multiple ways to use taxonomies throughout your project templates:
|
||||
|
||||
* Order the way content associated with a taxonomy term is displayed in a [taxonomy template](#taxonomy-templates)
|
||||
* Order the way the terms for a taxonomy are displayed in a [term template](#term-templates)
|
||||
* List a single content's taxonomy terms within a [single page template]
|
||||
|
||||
## Taxonomy templates
|
||||
|
||||
Taxonomy list page templates are lists and therefore have all the methods available to [list pages][lists].
|
||||
|
||||
### Taxonomy template lookup order
|
||||
|
||||
See [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
## Term templates
|
||||
|
||||
### Term template lookup order
|
||||
|
||||
See [Template Lookup](/templates/lookup-order/).
|
||||
|
||||
### Taxonomy methods
|
||||
|
||||
{{< list-pages-in-section path=/methods/taxonomy/ >}}
|
||||
|
||||
|
||||
### OrderedTaxonomy
|
||||
|
||||
Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order.
|
||||
|
||||
```go
|
||||
[]struct {
|
||||
Name string
|
||||
WeightedPages WeightedPages
|
||||
}
|
||||
```
|
||||
|
||||
Each element of the slice has:
|
||||
|
||||
.Term
|
||||
: The Term used.
|
||||
|
||||
.WeightedPages
|
||||
: A slice of Weighted Pages.
|
||||
|
||||
.Count
|
||||
: The number of pieces of content assigned to this term.
|
||||
|
||||
.Page
|
||||
: Returns a page reference for this term.
|
||||
|
||||
.Pages
|
||||
: All Pages assigned to this term. All [list methods][renderlists] are available to this.
|
||||
|
||||
## WeightedPages
|
||||
|
||||
WeightedPages is simply a slice of WeightedPage.
|
||||
|
||||
```go
|
||||
type WeightedPages []WeightedPage
|
||||
```
|
||||
|
||||
.Count
|
||||
: The number of pieces of content assigned to this term.
|
||||
|
||||
.Page
|
||||
: Returns a page reference for this term.
|
||||
|
||||
.Pages
|
||||
: Returns a slice of pages, which then can be ordered using any of the [list methods][renderlists].
|
||||
|
||||
## Displaying custom metadata in taxonomy terms templates
|
||||
|
||||
If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in its front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-metadata-to-a-taxonomy-or-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by ranging over the page collection returned by the [`Pages`] method:
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
||||
{{ .Params.wikipedia }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
## Order taxonomies
|
||||
|
||||
Taxonomies can be ordered by either alphabetical key or by the number of content pieces assigned to that key.
|
||||
|
||||
### Order alphabetically example
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Data.Terms.Alphabetical }}
|
||||
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
## Order content within taxonomies
|
||||
|
||||
Hugo uses both `date` and `weight` to order content within taxonomies.
|
||||
|
||||
Each piece of content in Hugo can optionally be assigned a date. It can also be assigned a weight for each taxonomy it is assigned to.
|
||||
|
||||
When iterating over content within taxonomies, the default sort is the same as that used for section and list pages: first by weight, then by date. This means that if the weights for two pieces of content are the same, then the more recent content will be displayed first.
|
||||
|
||||
The default weight for any piece of content is 0. Zero means "does not have a weight", not "has a weight of numerical value zero".
|
||||
|
||||
Weights of zero are thus treated specially: if two pages have unequal weights, and one of them is zero, then the zero-weighted page will always appear after the other one, regardless of the other's weight. Zero weights should thus be used with care: for example, if both positive and negative weights are used to extend a sequence in both directions, a zero-weighted page will appear not in the middle of the list, but at the end.
|
||||
|
||||
### Assign weight
|
||||
|
||||
Content can be assigned weight for each taxonomy that it's assigned to.
|
||||
|
||||
{{< code-toggle file=content/example.md fm=true >}}
|
||||
tags = [ "a", "b", "c" ]
|
||||
tags_weight = 22
|
||||
categories = ["d"]
|
||||
title = "Example"
|
||||
categories_weight = 44
|
||||
{{< /code-toggle >}}
|
||||
|
||||
The convention is `taxonomyname_weight`.
|
||||
|
||||
In the above example, this piece of content has a weight of 22 which applies to the sorting when rendering the pages assigned to the "a", "b" and "c" values of the 'tag' taxonomy.
|
||||
|
||||
It has also been assigned the weight of 44 when rendering the 'd' category.
|
||||
|
||||
With this the same piece of content can appear in different positions in different taxonomies.
|
||||
|
||||
Currently taxonomies only support the default ordering of content which is weight -> date.
|
||||
|
||||
There are two different templates that the use of taxonomies will require you to provide.
|
||||
|
||||
Both templates are covered in detail in the templates section.
|
||||
|
||||
A [list template](/templates/lists/) is any template that will be used to render multiple pieces of content in a single html page. This template will be used to generate all the automatically created taxonomy pages.
|
||||
|
||||
A [taxonomy template](/templates/taxonomy-templates/) is a template used to
|
||||
generate the list of terms for a given template.
|
||||
|
||||
There are four common ways you can display the data in your
|
||||
taxonomies in addition to the automatic taxonomy pages created by hugo
|
||||
using the [list templates](/templates/lists/):
|
||||
|
||||
1. For a given piece of content, you can list the terms attached
|
||||
2. For a given piece of content, you can list other content with the same
|
||||
term
|
||||
3. You can list all terms for a taxonomy
|
||||
4. You can list all taxonomies (with their terms)
|
||||
|
||||
## List terms assigned to a page
|
||||
|
||||
List the terms assigned to a page using the `.Page.GetTerms` method.
|
||||
|
||||
To render an unordered list:
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomy := "tags" }}
|
||||
{{ with .GetTerms $taxonomy }}
|
||||
<p>{{ (site.GetPage $taxonomy).LinkTitle }}:</p>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
To render a comma-delimited list:
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomy := "tags" }}
|
||||
{{ with .GetTerms $taxonomy }}
|
||||
<p>
|
||||
{{ (site.GetPage $taxonomy).LinkTitle }}:
|
||||
{{ range $k, $_ := . -}}
|
||||
{{ if $k }}, {{ end }}
|
||||
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
||||
{{- end }}
|
||||
</p>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## List content with the same taxonomy term
|
||||
|
||||
If you are using a taxonomy for something like a series of posts, you can list individual pages associated with the same term. For example:
|
||||
|
||||
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Taxonomies.series.golang }}
|
||||
<li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
## List all content in a given taxonomy
|
||||
|
||||
This would be very useful in a sidebar as “featured content”. You could even have different sections of “featured content” by assigning different terms to the content.
|
||||
|
||||
```go-html-template
|
||||
<section id="menu">
|
||||
<ul>
|
||||
{{ range $term, $taxonomy := .Site.Taxonomies.featured }}
|
||||
<li>{{ $term }}</li>
|
||||
<ul>
|
||||
{{ range $taxonomy.Pages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</section>
|
||||
```
|
||||
|
||||
## Render a site's taxonomies
|
||||
|
||||
The following example displays all terms in a site's tags taxonomy:
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Taxonomies.tags }}
|
||||
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms.
|
||||
|
||||
{{< code file=layouts/partials/all-taxonomies.html >}}
|
||||
{{ with .Site.Taxonomies }}
|
||||
{{ $numberOfTerms := 0 }}
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ $numberOfTerms = len . | add $numberOfTerms }}
|
||||
{{ end }}
|
||||
|
||||
{{ if gt $numberOfTerms 0 }}
|
||||
<ul>
|
||||
{{ range $taxonomy, $terms := . }}
|
||||
{{ with $terms }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $term, $weightedPages := . }}
|
||||
<li>
|
||||
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
|
||||
<ul>
|
||||
{{ range $weightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
[`Pages`]: /methods/page/pages/
|
||||
[getpage]: /methods/page/getpage/
|
||||
[lists]: /templates/lists/
|
||||
[renderlists]: /templates/lists/
|
||||
[single page template]: /templates/single-page-templates/
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
title: Taxonomy templates
|
||||
description: Create a taxonomy template to render a list of terms.
|
||||
categories: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 90
|
||||
weight: 90
|
||||
toc: true
|
||||
aliases: [/taxonomies/displaying/,/templates/terms/,/indexes/displaying/,/taxonomies/templates/,/indexes/ordering/, /templates/taxonomies/, /templates/taxonomy-templates/]
|
||||
---
|
||||
|
||||
The [taxonomy] template below inherits the site's shell from the [base template], and renders a list of [terms] in the current taxonomy.
|
||||
|
||||
[taxonomy]: /getting-started/glossary/#taxonomy
|
||||
[terms]: /getting-started/glossary/#term
|
||||
[base template]: /templates/types/
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Review the [template lookup order] to select a template path that provides the desired level of specificity.
|
||||
|
||||
[template lookup order]: /templates/lookup-order/#taxonomy-templates
|
||||
|
||||
In the example above, the taxonomy and term will be capitalized if their respective pages are not backed by files. You can disable this in your site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
capitalizeListTitles = false
|
||||
{{< /code-toggle >}}
|
||||
|
||||
## Data object
|
||||
|
||||
Use these methods on the `Data` object within a taxonomy template.
|
||||
|
||||
Singular
|
||||
: (`string`) Returns the singular name of the taxonomy.
|
||||
|
||||
```go-html-template
|
||||
{{ .Data.Singular }} → tag
|
||||
```
|
||||
|
||||
Plural
|
||||
: (`string`) Returns the plural name of the taxonomy.
|
||||
|
||||
```go-html-template
|
||||
{{ .Data.Plural }} → tags
|
||||
```
|
||||
|
||||
Terms
|
||||
: (`page.Taxonomy`) Returns the `Taxonomy` object, consisting of a map of terms and the [weighted pages] associated with each term.
|
||||
|
||||
[weighted pages]: /getting-started/glossary/#weighted-page
|
||||
|
||||
```go-html-template
|
||||
{{ $taxonomyObject := .Data.Terms }}
|
||||
```
|
||||
|
||||
Once we have the `Taxonomy` object, we can call any of its [methods], allowing us to sort alphabetically or by term count.
|
||||
|
||||
[methods]: /methods/taxonomy/
|
||||
|
||||
## Sort alphabetically
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list alphabetically by term, and displays the number of pages associated with each term.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Data.Terms.Alphabetical }}
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
## Sort by term count
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list by the number of pages associated with each term, and displays the number of pages associated with each term.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Data.Terms.ByCount }}
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
## Include content links
|
||||
|
||||
The [`Alphabetical`] and [`ByCount`] methods used in the previous examples return an [ordered taxonomy], so we can also list the content to which each term is assigned.
|
||||
|
||||
[ordered taxonomy]: /getting-started/glossary/#ordered-taxonomy
|
||||
[`Alphabetical`]: /methods/taxonomy/alphabetical/
|
||||
[`ByCount`]: /methods/taxonomy/bycount/
|
||||
|
||||
The taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy. Hugo sorts the list by the number of pages associated with each term, displays the number of pages associated with each term, then lists the content to which each term is assigned.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Data.Terms.ByCount }}
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
|
||||
<ul>
|
||||
{{ range .WeightedPages }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
## Display metadata
|
||||
|
||||
Display metadata about each term by creating a corresponding branch bundle in the content directory.
|
||||
|
||||
For example, create an "authors" taxonomy:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[taxonomies]
|
||||
author = 'authors'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Then create content with one [branch bundle] for each term:
|
||||
|
||||
[branch bundle]: /getting-started/glossary/#branch-bundle
|
||||
|
||||
```text
|
||||
content/
|
||||
└── authors/
|
||||
├── jsmith/
|
||||
│ ├── _index.md
|
||||
│ └── portrait.jpg
|
||||
└── rjones/
|
||||
├── _index.md
|
||||
└── portrait.jpg
|
||||
```
|
||||
|
||||
Then add front matter to each term page:
|
||||
|
||||
{{< code-toggle file=content/authors/jsmith/_index.md fm=true >}}
|
||||
title = "John Smith"
|
||||
affiliation = "University of Chicago"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Then create a taxonomy template specific to the "authors" taxonomy:
|
||||
|
||||
{{< code file=layouts/authors/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Data.Terms.Alphabetical }}
|
||||
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></h2>
|
||||
<p>Affiliation: {{ .Page.Params.Affiliation }}</p>
|
||||
{{ with .Page.Resources.Get "portrait.jpg" }}
|
||||
{{ with .Fill "100x100" }}
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="portrait">
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
In the example above we list each author including their affiliation and portrait.
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
title: Term templates
|
||||
description: Create a term template to render a list of pages associated with the current term.
|
||||
categories: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 100
|
||||
weight: 100
|
||||
toc: true
|
||||
---
|
||||
|
||||
The [term] template below inherits the site's shell from the [base template], and renders a list of pages associated with the current term.
|
||||
|
||||
[term]: /getting-started/glossary/#term
|
||||
[base template]: /templates/types/
|
||||
|
||||
{{< code file=layouts/_default/term.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Review the [template lookup order] to select a template path that provides the desired level of specificity.
|
||||
|
||||
[template lookup order]: /templates/lookup-order/#taxonomy-templates
|
||||
|
||||
In the example above, the term will be capitalized if its respective page is not backed by a file. You can disable this in your site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
capitalizeListTitles = false
|
||||
{{< /code-toggle >}}
|
||||
|
||||
## Data object
|
||||
|
||||
Use these methods on the `Data` object within a term template.
|
||||
|
||||
Singular
|
||||
: (`string`) Returns the singular name of the taxonomy.
|
||||
|
||||
```go-html-template
|
||||
{{ .Data.Singular }} → tag
|
||||
```
|
||||
|
||||
Plural
|
||||
: (`string`) Returns the plural name of the taxonomy.
|
||||
|
||||
```go-html-template
|
||||
{{ .Data.Plural }} → tags
|
||||
```
|
||||
|
||||
Term
|
||||
: (`string`) Returns the name of the term.
|
||||
|
||||
```go-html-template
|
||||
{{ .Data.Term }} → fiction
|
||||
```
|
||||
|
||||
## Display metadata
|
||||
|
||||
Display metadata about each term by creating a corresponding branch bundle in the content directory.
|
||||
|
||||
For example, create an "authors" taxonomy:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[taxonomies]
|
||||
author = 'authors'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Then create content with one [branch bundle] for each term:
|
||||
|
||||
[branch bundle]: /getting-started/glossary/#branch-bundle
|
||||
|
||||
```text
|
||||
content/
|
||||
└── authors/
|
||||
├── jsmith/
|
||||
│ ├── _index.md
|
||||
│ └── portrait.jpg
|
||||
└── rjones/
|
||||
├── _index.md
|
||||
└── portrait.jpg
|
||||
```
|
||||
|
||||
Then add front matter to each term page:
|
||||
|
||||
{{< code-toggle file=content/authors/jsmith/_index.md fm=true >}}
|
||||
title = "John Smith"
|
||||
affiliation = "University of Chicago"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Then create a term template specific to the "authors" taxonomy:
|
||||
|
||||
{{< code file=layouts/authors/term.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
<p>Affiliation: {{ .Params.affiliation }}</p>
|
||||
{{ with .Resources.Get "portrait.jpg" }}
|
||||
{{ with .Fill "100x100" }}
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="portrait">
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
In the example above we display the author with their affiliation and portrait, then a list of associated content.
|
||||
@@ -0,0 +1,284 @@
|
||||
---
|
||||
title: Template types
|
||||
linkTitle: Template types
|
||||
description: Create templates of different types to render your content, resources, and data.
|
||||
categories: [templates]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: templates
|
||||
weight: 30
|
||||
weight: 30
|
||||
toc: true
|
||||
aliases: ['/templates/lists/']
|
||||
---
|
||||
|
||||
[](site-hierarchy.svg)
|
||||
|
||||
## Structure
|
||||
|
||||
Create templates in the layouts directory in the root of your project.
|
||||
|
||||
Although your site may not require each of these templates, the example below is typical for a site of medium complexity.
|
||||
|
||||
```text
|
||||
layouts/
|
||||
├── _default/
|
||||
│ ├── _markup/
|
||||
│ │ ├── render-image.html <-- render hook
|
||||
│ │ └── render-link.html <-- render hook
|
||||
│ ├── baseof.html
|
||||
│ ├── home.html
|
||||
│ ├── section.html
|
||||
│ ├── single.html
|
||||
│ ├── taxonomy.html
|
||||
│ └── term.html
|
||||
├── articles/
|
||||
│ └── card.html <-- content view
|
||||
├── partials/
|
||||
│ ├── footer.html
|
||||
│ └── header.html
|
||||
└── shortcodes/
|
||||
├── audio.html
|
||||
└── video.html
|
||||
```
|
||||
|
||||
Hugo's [template lookup order] determines the template path, allowing you to create unique templates for any page.
|
||||
|
||||
[template lookup order]: /templates/lookup-order/
|
||||
|
||||
{{% note %}}
|
||||
You must have thorough understanding of the [template lookup order] when creating templates. Template selection is based on template type, page kind, content type, section, language, and output format.
|
||||
|
||||
[template lookup order]: /templates/lookup-order/
|
||||
{{% /note %}}
|
||||
|
||||
The purpose of each template type is described below.
|
||||
|
||||
## Base
|
||||
|
||||
Base templates reduce duplicate code by wrapping other templates within a shell.
|
||||
|
||||
For example, the base template below calls the [partial] function to include partial templates for the `head`, `header`, and `footer` elements of each page, and it uses the [block] function to include `home`, `single`, `section`, `taxonomy`, and `term` templates within the `main` element of each page.
|
||||
|
||||
[block]: /functions/go-template/block/
|
||||
[partial]: /functions/partials/include/
|
||||
|
||||
{{< code file=layouts/_default/baseof.html >}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ or site.Language.LanguageCode }}" dir="{{ or site.Language.LanguageDirection `ltr` }}">
|
||||
<head>
|
||||
{{ partial "head.html" . }}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
{{ partial "header.html" . }}
|
||||
</header>
|
||||
<main>
|
||||
{{ block "main" . }}{{ end }}
|
||||
</main>
|
||||
<footer>
|
||||
{{ partial "footer.html" . }}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [base templates](/templates/base/).
|
||||
|
||||
## Home
|
||||
|
||||
A home template renders your site's home page. For a single page site this is the only required template.
|
||||
|
||||
For example, the home template below inherits the site's shell from the base template, and renders the home page content with a list of pages.
|
||||
|
||||
{{< code file=layouts/_default/home.html >}}
|
||||
{{ define "main" }}
|
||||
{{ .Content }}
|
||||
{{ range site.RegularPages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% include "templates/_common/filter-sort-group.md" %}}
|
||||
|
||||
Learn more about [home templates](/templates/home/).
|
||||
|
||||
## Single
|
||||
|
||||
A single template renders a single page.
|
||||
|
||||
For example, the single template below inherits the site's shell from the base template, and renders the title and content of each page.
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [single templates](/templates/single/).
|
||||
|
||||
## Section
|
||||
|
||||
A section template typically renders a list of pages within a section.
|
||||
|
||||
For example, the section template below inherits the site's shell from the base template, and renders a list of pages in the current section.
|
||||
|
||||
{{< code file=layouts/_default/section.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% include "templates/_common/filter-sort-group.md" %}}
|
||||
|
||||
Learn more about [section templates](/templates/section/).
|
||||
|
||||
## Taxonomy
|
||||
|
||||
A taxonomy template renders a list of terms in a [taxonomy].
|
||||
|
||||
[taxonomy]: /getting-started/glossary/#taxonomy
|
||||
|
||||
For example, the taxonomy template below inherits the site's shell from the base template, and renders a list of terms in the current taxonomy.
|
||||
|
||||
{{< code file=layouts/_default/taxonomy.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% include "templates/_common/filter-sort-group.md" %}}
|
||||
|
||||
Learn more about [taxonomy templates](/templates/taxonomy/).
|
||||
|
||||
## Term
|
||||
|
||||
A term template renders a list of pages associated with a [term].
|
||||
|
||||
[term]: /getting-started/glossary/#term
|
||||
|
||||
For example, the term template below inherits the site's shell from the base template, and renders a list of pages associated with the current term.
|
||||
|
||||
{{< code file=layouts/_default/term.html >}}
|
||||
{{ define "main" }}
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
{{ range .Pages }}
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% include "templates/_common/filter-sort-group.md" %}}
|
||||
|
||||
Learn more about [term templates](/templates/term/).
|
||||
|
||||
## Partial
|
||||
|
||||
A partial template is typically used to render a component of your site, though you may also create partial templates that return values.
|
||||
|
||||
{{% note %}}
|
||||
Unlike other template types, you cannot create partial templates to target a particular page kind, content type, section, language, or output format. Partial templates do not follow Hugo's [template lookup order].
|
||||
|
||||
[template lookup order]: /templates/lookup-order/
|
||||
{{% /note %}}
|
||||
|
||||
For example, the partial template below renders copyright information.
|
||||
|
||||
{{< code file=layouts/partials/footer.html >}}
|
||||
<p>Copyright {{ now.Year }}. All rights reserved.</p>
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [partial templates](/templates/partial/).
|
||||
|
||||
## Content view
|
||||
|
||||
A content view template is similar to a partial template, invoked by calling the [`Render`] method on a `Page` object. Unlike partial templates, content view templates:
|
||||
|
||||
- Automatically inherit the context of the current page
|
||||
- Follow a lookup order allowing you to target a given content type or section
|
||||
|
||||
[`Render`]: /methods/page/render/
|
||||
|
||||
For example, the home template below inherits the site's shell from the base template, and renders a card component for each page within the "articles" section of your site.
|
||||
|
||||
{{< code file=layouts/_default/home.html >}}
|
||||
{{ define "main" }}
|
||||
{{ .Content }}
|
||||
<ul>
|
||||
{{ range where site.RegularPages "Section" "articles" }}
|
||||
{{ .Render "card" }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file=layouts/articles/card.html >}}
|
||||
<div class="card">
|
||||
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||
{{ .Summary }}
|
||||
</div>
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [content view templates](/templates/content-view/).
|
||||
|
||||
## Render hook
|
||||
|
||||
A render hook template overrides the conversion of Markdown to HTML.
|
||||
|
||||
For example, the render hook template below adds a `rel` attribute to external links.
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-link.html >}}
|
||||
{{- $u := urls.Parse .Destination -}}
|
||||
<a href="{{ .Destination | safeURL }}"
|
||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||
{{- if $u.IsAbs }} rel="external"{{ end -}}
|
||||
>
|
||||
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
|
||||
</a>
|
||||
{{- /* chomp trailing newline */ -}}
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [render hook templates](/render-hooks/).
|
||||
|
||||
## Shortcode
|
||||
|
||||
A shortcode template is used to render a component of your site. Unlike partial templates, shortcode templates are called from content pages.
|
||||
|
||||
For example, the shortcode template below renders an audio element from a [global resource].
|
||||
|
||||
[global resource]: /getting-started/glossary/#global-resource
|
||||
|
||||
{{< code file=layouts/shortcodes/audio.html >}}
|
||||
{{ with resources.Get (.Get "src") }}
|
||||
<audio controls preload="auto" src="{{ .RelPermalink }}"></audio>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
Call the shortcode from your content page:
|
||||
|
||||
{{< code file=content/example.md >}}
|
||||
{{</* audio src="audio/test.mp3" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
Learn more about [shortcode templates](/templates/shortcode/).
|
||||
|
||||
## Other
|
||||
|
||||
Use other specialized templates to create:
|
||||
|
||||
- [Sitemaps](/templates/sitemap)
|
||||
- [RSS feeds](/templates/rss/)
|
||||
- [404 error pages](/templates/404/)
|
||||
- [robots.txt files](/templates/robots/)
|
||||
|
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 193 KiB |
Reference in New Issue
Block a user