mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 16:27:15 -04:00
content: Improve some examples
This commit is contained in:
parent
8ebaa53f93
commit
51aa1ae73a
@ -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:
|
||||
|
||||
{{< 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']
|
||||
{{< /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:
|
||||
|
||||
{{< 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']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
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']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
|
@ -13,7 +13,7 @@ Specify the `layout` field in front matter to target a particular template. See&
|
||||
|
||||
[details]: /templates/lookup-order/#target-a-template
|
||||
|
||||
{{< code-toggle file=content/contact.md >}}
|
||||
{{< code-toggle file=content/contact.md fm=true >}}
|
||||
title = 'Contact'
|
||||
layout = 'contact'
|
||||
{{< /code-toggle >}}
|
||||
|
@ -9,31 +9,34 @@ 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'
|
||||
date = 2023-10-17T15:11:37-07:00
|
||||
[params]
|
||||
display_related = true
|
||||
key-with-hyphens = 'must use index function'
|
||||
[params.author]
|
||||
email = 'jsmith@example.org'
|
||||
name = 'John Smith'
|
||||
{{< /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
|
||||
{{ .Params.display_related }} → true
|
||||
{{ .Params.author.email }} → jsmith@example.org
|
||||
{{ .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" }} → 2023
|
||||
{{ index .Params "key-with-hyphens" }} → must use index function
|
||||
```
|
||||
|
||||
[`index`]: /functions/collections/indexfunction/
|
||||
[front matter fields]: /content-management/front-matter/#fields
|
||||
|
@ -26,7 +26,7 @@ To include the embedded template:
|
||||
|
||||
To use Hugo's Disqus template, first set up a single configuration value:
|
||||
|
||||
{{< code-toggle file="hugo" >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[services.disqus]
|
||||
shortname = 'your-disqus-shortname'
|
||||
{{</ 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"
|
||||
{{</ code-toggle >}}
|
||||
|
||||
{{< code-toggle file=content/blog/my-post.md >}}
|
||||
{{< code-toggle file=content/blog/my-post.md fm=true >}}
|
||||
title = "Post title"
|
||||
description = "Text about this post"
|
||||
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:
|
||||
|
||||
{{< code-toggle file="hugo" >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[params.social]
|
||||
twitter = "GoHugoIO"
|
||||
{{</ code-toggle >}}
|
||||
|
@ -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.
|
||||
|
||||
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'
|
||||
date = 2023-10-17T15:11:37-07:00
|
||||
[params]
|
||||
display_related = true
|
||||
key-with-hyphens = 'must use index function'
|
||||
[params.author]
|
||||
email = 'jsmith@example.org'
|
||||
name = 'John Smith'
|
||||
{{< /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
|
||||
{{ .Params.display_related }} → true
|
||||
{{ .Params.author.email }} → jsmith@example.org
|
||||
{{ .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
|
||||
[`else`]: /functions/go-template/else/
|
||||
[`end`]: /functions/go-template/end/
|
||||
[`if`]: /functions/go-template/if/
|
||||
[`index`]: /functions/collections/indexfunction/
|
||||
[`index`]: /functions/collections/indexfunction/
|
||||
[`or`]: /functions/go-template/or
|
||||
[`Page`]: /methods/page/
|
||||
[`partial`]: /functions/partials/include/
|
||||
@ -511,6 +522,7 @@ Access the custom page parameters by chaining the identifiers:
|
||||
[current context]: #current-context
|
||||
[embedded templates]: /templates/embedded/
|
||||
[front matter]: /content-management/front-matter/
|
||||
[front matter fields]: /content-management/front-matter/#fields
|
||||
[functions]: /functions/
|
||||
[functions]: /functions
|
||||
[go-templates]: /functions/go-template/
|
||||
|
@ -56,7 +56,7 @@ layouts/
|
||||
|
||||
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'
|
||||
layout = 'contact'
|
||||
{{< /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:
|
||||
|
||||
{{< code-toggle file=content/about.md >}}
|
||||
{{< code-toggle file=content/about.md fm=true >}}
|
||||
title = 'About'
|
||||
type = 'miscellaneous'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{< code-toggle file=content/contact.md >}}
|
||||
{{< code-toggle file=content/contact.md fm=true >}}
|
||||
title = 'Contact'
|
||||
type = 'miscellaneous'
|
||||
layout = 'contact'
|
||||
|
Loading…
x
Reference in New Issue
Block a user