Skip to content

Commit

Permalink
tpl: Add "param" shortcode
Browse files Browse the repository at this point in the history
Fixes #4010
  • Loading branch information
bep committed Nov 27, 2018
1 parent aded0f2 commit f37c5a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/content/en/content-management/shortcodes.md
Expand Up @@ -15,6 +15,7 @@ categories: [content management]
keywords: [markdown,content,shortcodes] keywords: [markdown,content,shortcodes]
draft: false draft: false
aliases: [/extras/shortcodes/] aliases: [/extras/shortcodes/]
testparam: "Hugo Rocks!"
toc: true toc: true
--- ---


Expand Down Expand Up @@ -240,6 +241,24 @@ Using the preceding `instagram` with `hidecaption` example above, the following
{{< instagram BWNjjyYFxVx hidecaption >}} {{< 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` ### `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. 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.
Expand Down
4 changes: 4 additions & 0 deletions tpl/tplimpl/embedded/templates.autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tpl/tplimpl/embedded/templates/shortcodes/param.html
@@ -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 -}}

0 comments on commit f37c5a2

Please sign in to comment.