siteparam: support nested parameters and text formatting #590

This commit is contained in:
Sören Weber 2023-07-26 22:29:03 +02:00
parent 80c1b4e04e
commit e9d3eb6489
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
5 changed files with 35 additions and 7 deletions

View file

@ -231,3 +231,5 @@ title = "Hugo Relearn Documentation"
# security reasons
mermaidInitialize = "{ \"securityLevel\": \"loose\" }"
mermaidZoom = true
[params.siteparam.test]
text = "A **nested** parameter <b>with</b> formatting"

View file

@ -32,6 +32,8 @@ This document shows you what's new in the latest release. For a detailed list of
In addition it offers some extensions. Currently only the `wrap` extension option is provided to control whether a code block should be wrapped or scrolled if to long to fit.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`siteparam` shortcode]({{% relref "shortcodes/siteparam" %}}) is now capable to display nested params aswell as adding support for text formatting.
---
## 5.16.0 (2023-06-10)

View file

@ -1,6 +1,6 @@
+++
description = "Get value of site params"
title = "Site Param"
title = "SiteParam"
+++
The `siteparam` shortcode prints values of site params.
@ -52,3 +52,26 @@ While the examples are using shortcodes with named parameter you are free to use
```
`editURL` value: {{% siteparam name="editURL" %}}
### Nested parameter with Markdown and HTML formatting
To use formatted parameter, add this in your `config.toml`:
````toml
[markup.goldmark.renderer]
unsafe = true
````
{{% tab title="config.toml" %}}
````toml
[params]
[params.siteparam.test]
text = "A **nested** parameter <b>with</b> formatting"
````
{{% /tab %}}
```go
Formatted parameter: {{%/* siteparam name="siteparam.test.text" */%}}
```
Formatted parameter: {{% siteparam name="siteparam.test.text" %}}

View file

@ -1,5 +1,5 @@
+++
descrption = "Get value o' ship parrrams varrriables 'n yer plank"
title = "Ship Param"
title = "SiteParam"
+++
{{< piratify >}}

View file

@ -1,10 +1,11 @@
{{- $context := .context }}
{{- $paramName := .name }}
{{- $paramNames := split .name "." }}
{{- with $context }}
{{- $siteParams := .Site.Params }}
{{- with $paramName }}
{{- with $siteParams }}
{{- index . (lower $paramName) }}
{{- $params := .Site.Params }}
{{- range $paramName := $paramNames }}
{{- with $params }}
{{- $params = index . (lower $paramName) }}
{{- end }}
{{- end }}
{{- $params | .RenderString }}
{{- end }}