content: Improve some examples

This commit is contained in:
Joe Mooring 2025-03-09 17:07:38 -07:00 committed by GitHub
parent 8ebaa53f93
commit 51aa1ae73a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 18 deletions

View File

@ -189,7 +189,7 @@ Create redirects from old URLs to new URLs with aliases:
Change the file name of an existing page, and create an alias from the previous URL to the new URL: Change the file name of an existing page, and create an alias from the previous URL to the new URL:
{{< code-toggle file=content/posts/new-file-name.md >}} {{< code-toggle file=content/posts/new-file-name.md fm=true >}}
aliases = ['/posts/previous-file-name'] aliases = ['/posts/previous-file-name']
{{< /code-toggle >}} {{< /code-toggle >}}
@ -201,13 +201,13 @@ Each of these directory-relative aliases is equivalent to the site-relative alia
You can create more than one alias to the current page: You can create more than one alias to the current page:
{{< code-toggle file=content/posts/new-file-name.md >}} {{< code-toggle file=content/posts/new-file-name.md fm=true >}}
aliases = ['previous-file-name','original-file-name'] aliases = ['previous-file-name','original-file-name']
{{< /code-toggle >}} {{< /code-toggle >}}
In a multilingual site, use a directory-relative alias, or include the language prefix with a site-relative alias: In a multilingual site, use a directory-relative alias, or include the language prefix with a site-relative alias:
{{< code-toggle file=content/posts/new-file-name.de.md >}} {{< code-toggle file=content/posts/new-file-name.de.md fm=true >}}
aliases = ['/de/posts/previous-file-name'] aliases = ['/de/posts/previous-file-name']
{{< /code-toggle >}} {{< /code-toggle >}}

View File

@ -13,7 +13,7 @@ Specify the `layout` field in front matter to target a particular template. See&
[details]: /templates/lookup-order/#target-a-template [details]: /templates/lookup-order/#target-a-template
{{< code-toggle file=content/contact.md >}} {{< code-toggle file=content/contact.md fm=true >}}
title = 'Contact' title = 'Contact'
layout = 'contact' layout = 'contact'
{{< /code-toggle >}} {{< /code-toggle >}}

View File

@ -9,31 +9,34 @@ params:
signatures: [PAGE.Params] signatures: [PAGE.Params]
--- ---
With this front matter: By way of example, consider this front matter:
{{< code-toggle file=content/news/annual-conference.md >}} {{< code-toggle file=content/annual-conference.md fm=true >}}
title = 'Annual conference' title = 'Annual conference'
date = 2023-10-17T15:11:37-07:00 date = 2023-10-17T15:11:37-07:00
[params] [params]
display_related = true display_related = true
key-with-hyphens = 'must use index function'
[params.author] [params.author]
email = 'jsmith@example.org' email = 'jsmith@example.org'
name = 'John Smith' name = 'John Smith'
{{< /code-toggle >}} {{< /code-toggle >}}
The `title` and `date` fields are standard parameters---the other fields are user-defined. The `title` and `date` fields are standard [front matter fields], while the other fields are user-defined.
Access the custom parameters by [chaining](g) the [identifiers](g): Access the custom fields by [chaining](g) the [identifiers](g) when needed:
```go-html-template ```go-html-template
{{ .Params.display_related }} → true {{ .Params.display_related }} → true
{{ .Params.author.email }} → jsmith@example.org
{{ .Params.author.name }} → John Smith {{ .Params.author.name }} → John Smith
``` ```
In the template example above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function: In the template example above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function:
```go-html-template ```go-html-template
{{ index .Params "key-with-hyphens" }} → 2023 {{ index .Params "key-with-hyphens" }} → must use index function
``` ```
[`index`]: /functions/collections/indexfunction/ [`index`]: /functions/collections/indexfunction/
[front matter fields]: /content-management/front-matter/#fields

View File

@ -26,7 +26,7 @@ To include the embedded template:
To use Hugo's Disqus template, first set up a single configuration value: To use Hugo's Disqus template, first set up a single configuration value:
{{< code-toggle file="hugo" >}} {{< code-toggle file=hugo >}}
[services.disqus] [services.disqus]
shortname = 'your-disqus-shortname' shortname = 'your-disqus-shortname'
{{</ code-toggle >}} {{</ code-toggle >}}
@ -186,7 +186,7 @@ Hugo's X (Twitter) Card template is configured using a mix of configuration sett
description = "Text about my cool site" description = "Text about my cool site"
{{</ code-toggle >}} {{</ code-toggle >}}
{{< code-toggle file=content/blog/my-post.md >}} {{< code-toggle file=content/blog/my-post.md fm=true >}}
title = "Post title" title = "Post title"
description = "Text about this post" description = "Text about this post"
images = ["post-cover.png"] images = ["post-cover.png"]
@ -200,7 +200,7 @@ Hugo uses the page title and description for the card's title and description fi
Set the value of `twitter:site` in your site configuration: Set the value of `twitter:site` in your site configuration:
{{< code-toggle file="hugo" >}} {{< code-toggle file=hugo >}}
[params.social] [params.social]
twitter = "GoHugoIO" twitter = "GoHugoIO"
{{</ code-toggle >}} {{</ code-toggle >}}

View File

@ -471,30 +471,41 @@ Access the custom site parameters by chaining the identifiers:
See documentation for the [`Params`](/methods/page/params/) method on a `Page` object. See documentation for the [`Params`](/methods/page/params/) method on a `Page` object.
With this front matter: By way of example, consider this front matter:
{{< code-toggle file=content/news/annual-conference.md >}} {{< code-toggle file=content/annual-conference.md fm=true >}}
title = 'Annual conference' title = 'Annual conference'
date = 2023-10-17T15:11:37-07:00 date = 2023-10-17T15:11:37-07:00
[params] [params]
display_related = true display_related = true
key-with-hyphens = 'must use index function'
[params.author] [params.author]
email = 'jsmith@example.org' email = 'jsmith@example.org'
name = 'John Smith' name = 'John Smith'
{{< /code-toggle >}} {{< /code-toggle >}}
Access the custom page parameters by chaining the identifiers: The `title` and `date` fields are standard [front matter fields], while the other fields are user-defined.
Access the custom fields by [chaining](g) the [identifiers](g) when needed:
```go-html-template ```go-html-template
{{ .Params.display_related }} → true {{ .Params.display_related }} → true
{{ .Params.author.email }} → jsmith@example.org
{{ .Params.author.name }} → John Smith {{ .Params.author.name }} → John Smith
``` ```
In the template example above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function:
```go-html-template
{{ index .Params "key-with-hyphens" }} → must use index function
```
[`and`]: /functions/go-template/and [`and`]: /functions/go-template/and
[`else`]: /functions/go-template/else/ [`else`]: /functions/go-template/else/
[`end`]: /functions/go-template/end/ [`end`]: /functions/go-template/end/
[`if`]: /functions/go-template/if/ [`if`]: /functions/go-template/if/
[`index`]: /functions/collections/indexfunction/ [`index`]: /functions/collections/indexfunction/
[`index`]: /functions/collections/indexfunction/
[`or`]: /functions/go-template/or [`or`]: /functions/go-template/or
[`Page`]: /methods/page/ [`Page`]: /methods/page/
[`partial`]: /functions/partials/include/ [`partial`]: /functions/partials/include/
@ -511,6 +522,7 @@ Access the custom page parameters by chaining the identifiers:
[current context]: #current-context [current context]: #current-context
[embedded templates]: /templates/embedded/ [embedded templates]: /templates/embedded/
[front matter]: /content-management/front-matter/ [front matter]: /content-management/front-matter/
[front matter fields]: /content-management/front-matter/#fields
[functions]: /functions/ [functions]: /functions/
[functions]: /functions [functions]: /functions
[go-templates]: /functions/go-template/ [go-templates]: /functions/go-template/

View File

@ -56,7 +56,7 @@ layouts/
But the contact page probably has a form and requires a different template. In the front matter specify `layout`: But the contact page probably has a form and requires a different template. In the front matter specify `layout`:
{{< code-toggle file=content/contact.md >}} {{< code-toggle file=content/contact.md fm=true >}}
title = 'Contact' title = 'Contact'
layout = 'contact' layout = 'contact'
{{< /code-toggle >}} {{< /code-toggle >}}
@ -72,12 +72,12 @@ layouts/
As a content type, the word `page` is vague. Perhaps `miscellaneous` would be better. Add `type` to the front matter of each page: As a content type, the word `page` is vague. Perhaps `miscellaneous` would be better. Add `type` to the front matter of each page:
{{< code-toggle file=content/about.md >}} {{< code-toggle file=content/about.md fm=true >}}
title = 'About' title = 'About'
type = 'miscellaneous' type = 'miscellaneous'
{{< /code-toggle >}} {{< /code-toggle >}}
{{< code-toggle file=content/contact.md >}} {{< code-toggle file=content/contact.md fm=true >}}
title = 'Contact' title = 'Contact'
type = 'miscellaneous' type = 'miscellaneous'
layout = 'contact' layout = 'contact'