mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
aded0f25fd
commit
f37c5a2567
3 changed files with 27 additions and 0 deletions
|
@ -15,6 +15,7 @@ categories: [content management]
|
|||
keywords: [markdown,content,shortcodes]
|
||||
draft: false
|
||||
aliases: [/extras/shortcodes/]
|
||||
testparam: "Hugo Rocks!"
|
||||
toc: true
|
||||
---
|
||||
|
||||
|
@ -240,6 +241,24 @@ Using the preceding `instagram` with `hidecaption` example above, the following
|
|||
{{< instagram BWNjjyYFxVx hidecaption >}}
|
||||
|
||||
|
||||
### `param`
|
||||
|
||||
Gets a value from the current `Page's` params set in front matter, with a fall back to the site param value. If will log an `ERROR` if the param with the given key could not be found in either.
|
||||
|
||||
```bash
|
||||
{{</* param testparam */>}}
|
||||
```
|
||||
|
||||
Since `testparam` is a param defined in front matter of this page wi the value `Hugo Rocks!`, the above will print:
|
||||
|
||||
{{< param testparam >}}
|
||||
|
||||
To access deeply nested params, use "dot syntax", e.g:
|
||||
|
||||
```bash
|
||||
{{</* param "my.nested.param" */>}}
|
||||
```
|
||||
|
||||
### `ref` and `relref`
|
||||
|
||||
These shortcodes will look up the pages by their relative path (e.g., `blog/post.md`) or their logical name (`post.md`) and return the permalink (`ref`) or relative permalink (`relref`) for the found page.
|
||||
|
|
4
tpl/tplimpl/embedded/templates.autogen.go
generated
4
tpl/tplimpl/embedded/templates.autogen.go
generated
|
@ -398,6 +398,10 @@ if (!doNotTrack) {
|
|||
</style>
|
||||
{{ end }}
|
||||
{{ end }}`},
|
||||
{`shortcodes/param.html`, `{{- $name := (.Get 0) -}}
|
||||
{{- with $name -}}
|
||||
{{- with ($.Page.Param .) }}{{ . }}{{ else }}{{ errorf "Param %q not found: %s" $name $.Position }}{{ end -}}
|
||||
{{- else }}{{ errorf "Missing param key: %s" $.Position }}{{ end -}}`},
|
||||
{`shortcodes/ref.html`, `{{ ref . .Params }}`},
|
||||
{`shortcodes/relref.html`, `{{ relref . .Params }}`},
|
||||
{`shortcodes/twitter.html`, `{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
||||
|
|
4
tpl/tplimpl/embedded/templates/shortcodes/param.html
Normal file
4
tpl/tplimpl/embedded/templates/shortcodes/param.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{- $name := (.Get 0) -}}
|
||||
{{- with $name -}}
|
||||
{{- with ($.Page.Param .) }}{{ . }}{{ else }}{{ errorf "Param %q not found: %s" $name $.Position }}{{ end -}}
|
||||
{{- else }}{{ errorf "Missing param key: %s" $.Position }}{{ end -}}
|
Loading…
Reference in a new issue