mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
feat: fix #58 - add site param shortcode
This commit is contained in:
parent
9071837183
commit
f2260fdace
3 changed files with 53 additions and 0 deletions
23
exampleSite/content/shortcodes/siteparam.en.md
Normal file
23
exampleSite/content/shortcodes/siteparam.en.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Site param
|
||||
description : "Get value of site params variables in your page."
|
||||
---
|
||||
|
||||
`siteparam` shortcode is used to help you print values of site params.
|
||||
|
||||
For instance, in this current site, the `editURL` variable is used in `config.toml`
|
||||
|
||||
```toml
|
||||
[params]
|
||||
editURL = "https://github.com/matcornic/hugo-theme-learn/edit/master/exampleSite/content/"
|
||||
```
|
||||
|
||||
Use the `siteparam` shortcode to display its value.
|
||||
|
||||
```
|
||||
`editURL` Value : {{%/* siteparam "editURL" */%}}
|
||||
```
|
||||
|
||||
is displayed as
|
||||
|
||||
`editURL` Value : {{% siteparam "editURL" %}}
|
23
exampleSite/content/shortcodes/siteparam.fr.md
Normal file
23
exampleSite/content/shortcodes/siteparam.fr.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Site param
|
||||
description : "Afficher la valeur d'un paramètre global du site dans votre page"
|
||||
---
|
||||
|
||||
Les shortcode `siteparam` est utilisé pour vous aider à afficher des valeurs provenant des paramètres globaux du site.
|
||||
|
||||
Par exemple, dans ce site, le paramètre `editURL` est utilisé dans le fichier `config.toml`
|
||||
|
||||
```toml
|
||||
[params]
|
||||
editURL = "https://github.com/matcornic/hugo-theme-learn/edit/master/exampleSite/content/"
|
||||
```
|
||||
|
||||
Utilisez le shortcode `siteparam` pour affichier sa valeur.
|
||||
|
||||
```
|
||||
Valeur de `editURL` : {{%/* siteparam "editURL" */%}}
|
||||
```
|
||||
|
||||
s'affiche comme
|
||||
|
||||
Valeur de `editURL` : {{% siteparam "editURL" %}}
|
7
layouts/shortcodes/siteparam.html
Normal file
7
layouts/shortcodes/siteparam.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{- $paramName := (.Get 0) -}}
|
||||
{{- $siteParams := .Site.Params -}}
|
||||
{{- with $paramName -}}
|
||||
{{- with $siteParams -}}
|
||||
{{- index . (lower $paramName) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
Loading…
Reference in a new issue