ref: f37c5a25676db89c0e804ccaac69bb392758192b
parent: aded0f25fd23a78804b10e127aebe0e4b6fed2ac
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Nov 27 11:53:11 EST 2018
tpl: Add "param" shortcode Fixes #4010
--- a/docs/content/en/content-management/shortcodes.md
+++ b/docs/content/en/content-management/shortcodes.md
@@ -15,6 +15,7 @@
keywords: [markdown,content,shortcodes]
draft: false
aliases: [/extras/shortcodes/]
+testparam: "Hugo Rocks!"
toc: true
---
@@ -239,6 +240,24 @@
{{< 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`
--- a/tpl/tplimpl/embedded/templates.autogen.go
+++ b/tpl/tplimpl/embedded/templates.autogen.go
@@ -398,6 +398,10 @@
</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 -}}
--- /dev/null
+++ b/tpl/tplimpl/embedded/templates/shortcodes/param.html
@@ -1,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 -}}
\ No newline at end of file