lcron
February 18, 2020, 2:52pm
1
I hope in the layout:
Custom functions.
Call the short code.
partial uses ‘$’ to access the global context.
{{with index $.Site.Data.img .name}}
.
{{else}}
/img/not-found.jpg
{{end}}
And then use it like this
{{partial "img" (dict "name" "image_name" "Site" $ .Site)}}
Why should things be so tedious if they could be reused?
I hope it can be used like this:
Custom function: img name = image_name
Call short code: call img name = image_name
Partial access to the global context: partial" img "dict (" name "" image_name ")
maiki
February 20, 2020, 4:57am
3
I don’t understand what you are asking.
lcron
February 20, 2020, 5:08am
4
It is a template that is used repeatedly. At present, such a syntax is cumbersome. Each call uses a dictionary to store parameters and also pass a Site variable. I hope to simplify this syntax and propose 3 solutions.
To replace it:
{{partial "img" (dict "name" "image_name" "Site" $ .Site)}}
maiki
February 20, 2020, 7:50am
5
Please follow the advice at Requesting Help and share a repo. Otherwise folks are gonna have a difficult time testing out possible solutions.
regis
February 20, 2020, 10:57am
6
Well you can use the global function site
instead of .Site
so your partial can now take a string for context:
{{ partial "img" "image-3.png" }}
lcron
February 20, 2020, 1:14pm
7
The site function instead of .Site is great, so you don’t need to do extra passes.
Hasn’t it been added to the document yet?