mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 23:12:10 -05:00
Expanded the Page Params section in variables.md
Expanded on the use of Page Params in the templates/variables.md documentation. Added sample code for something that keeps coming up on discuss.github.io
This commit is contained in:
parent
d158f7e339
commit
817d69487c
1 changed files with 20 additions and 0 deletions
|
@ -67,6 +67,26 @@ For example, the *tags* and *categories* taxonomies are accessed with:
|
||||||
|
|
||||||
**All Params are only accessible using all lowercase characters.**
|
**All Params are only accessible using all lowercase characters.**
|
||||||
|
|
||||||
|
This is particularly useful for the introduction of user defined fields in content files. For example, a Hugo website on book reviews could have in the front matter of <code>/content/review/book01.md</code>
|
||||||
|
|
||||||
|
---
|
||||||
|
...
|
||||||
|
affiliatelnk: "http://www.my-book-link.here"
|
||||||
|
recommendedby: "my Mother"
|
||||||
|
---
|
||||||
|
|
||||||
|
Which would then be accessible to a template at <code>/theme/yourtheme/review/single.html</code>, for example, through <code>.Params.affiliatelnk</code> and <code>.Params.recommendedby</code>, respectively. Two common situations where these could be introduced are as a value of a certain attribute (like <code>href=""</code> below) or by itself if it will be displayed. Sample syntaxes include:
|
||||||
|
|
||||||
|
<h3><a href="{{ printf "%s" $.Params.affiliatelnk }}">Buy this book</a></h3>
|
||||||
|
<p>It was recommended by {{ .Params.recommendedby }}.</p>
|
||||||
|
|
||||||
|
which would render
|
||||||
|
|
||||||
|
<h3><a href="http://www.my-book-link.here">Buy this book</a></h3>
|
||||||
|
<p>It was recommended by my Mother.</p>
|
||||||
|
|
||||||
|
**See also:** [cross-references]({{% ref "content/archetypes.md" %}}) for consistency of `Params` accross pieces of content.
|
||||||
|
|
||||||
### Param method
|
### Param method
|
||||||
In Hugo you can declare params both for the site and the individual page. A common use case is to have a general value for the site and a more specific value for some of the pages (i.e. an image).
|
In Hugo you can declare params both for the site and the individual page. A common use case is to have a general value for the site and a more specific value for some of the pages (i.e. an image).
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue