diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-01-17 12:51:46 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-01-17 12:51:46 +0100 |
commit | b661132e0ac651fa229511f05f58554717f4d0d0 (patch) | |
tree | 7e1b3ff9ca2f2284809f840c067edc308aa35f52 /docs/content/en/functions | |
parent | d595419031b247d6f15a615f6e70b1956ff8eab1 (diff) | |
parent | ef6f101e75256c3bb88a6f1f3b5c1273bf8d7382 (diff) | |
download | hugo-b661132e0ac651fa229511f05f58554717f4d0d0.tar.gz hugo-b661132e0ac651fa229511f05f58554717f4d0d0.zip |
Merge commit 'ef6f101e75256c3bb88a6f1f3b5c1273bf8d7382'
Diffstat (limited to 'docs/content/en/functions')
-rw-r--r-- | docs/content/en/functions/images/index.md | 2 | ||||
-rw-r--r-- | docs/content/en/functions/param.md | 59 |
2 files changed, 34 insertions, 27 deletions
diff --git a/docs/content/en/functions/images/index.md b/docs/content/en/functions/images/index.md index 0cf45b6ee..e7fc50f7e 100644 --- a/docs/content/en/functions/images/index.md +++ b/docs/content/en/functions/images/index.md @@ -60,7 +60,7 @@ You can load a custom font if needed. Load the font as a Hugo `Resource` and set ```go-html-template -{{ $font := resources.Get "https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Black.ttf" }} +{{ $font := resources.GetRemote "https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Black.ttf" }} {{ $img := resources.Get "/images/background.png"}} {{ $img = $img.Filter (images.Text "Hugo rocks!" (dict "font" $font diff --git a/docs/content/en/functions/param.md b/docs/content/en/functions/param.md index 5387647d2..4f1764814 100644 --- a/docs/content/en/functions/param.md +++ b/docs/content/en/functions/param.md @@ -1,40 +1,47 @@ --- title: .Param -description: Calls page or site variables into your template. -date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-04-30 -keywords: ["front matter"] +description: Returns a page parameter, falling back to a site parameter if present. +signature: ['.Param KEY'] categories: [functions] +keywords: ['front matter', 'params'] menu: docs: - parent: "functions" -toc: -signature: [".Param KEY"] -workson: [] -hugoversion: -relatedfuncs: [default] -deprecated: false -draft: false + parent: 'functions' aliases: [] --- -In Hugo, you can declare [site-wide params][sitevars] (i.e. in your [configuration]), as well as params for [individual pages][pagevars]. +The `.Param` method on `.Page` looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY` in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the `.Param` method returns `nil`. -A common use case is to have a general value for the site and a more specific value for some of the pages (e.g., an image). +Site and theme developers commonly set parameters at the site level, allowing content authors to override those parameters at the page level. -You can use the `.Param` method to call these values into your template. The following will first look for an `image` param in a specific content's [front matter]. If not found, Hugo will look for an `image` param in your site's configuration: +For example, to show a table of contents on every page, but allow authors to hide the table of contents as needed: -``` -$.Param "image" -``` +**Configuration** -{{% note %}} -The `Param` method may not consider empty strings in a content's front matter as "not found." If you are setting preconfigured front matter fields to empty strings using Hugo's archetypes, it may be best to use the [`default` function](/functions/default/) instead of `Param`. See the [related issue on GitHub](https://github.com/gohugoio/hugo/issues/3366). -{{% /note %}} +{{< code-toggle file="config" copy=false >}} +[params] +display_toc = true +{{< /code-toggle >}} +**Content** -[configuration]: /getting-started/configuration/ -[front matter]: /content-management/front-matter/ -[pagevars]: /variables/page/ -[sitevars]: /variables/site/ +{{< code-toggle file="content/about.md" fm=true copy=false >}} +title = 'About' +date = 2023-01-01 +draft = false +display_toc = false +{{< /code-toggle >}} + +**Template** + +{{< code file="layouts/_default/single.html" copy="false" >}} +{{ if .Param "display_toc" }} + {{ .TableOfContents }} +{{ end }} +{{< /code >}} + +The `.Param` method returns the value associated with the given `KEY`, regardless of whether the value is truthy or falsy. If you need to ignore falsy values, use this construct instead: + +{{< code file="layouts/_default/single.html" copy="false" >}} +{{ or .Params.foo site.Params.foo }} +{{< /code >}} |