Hi All,
I’ve having some trouble, and either my google fu is weak (likely) or something else is up.
I’m trying to access .Site.Params. defined in config.toml from a partial in a custom theme I’m working on - but it I can’t access any vars.
If I move the code to a layout file (instead of a partial) it works.
The partial is definitely being loaded (I can see the plain html from the partial make it into the final build of the site).
Any ideas what I’m doing wrong?
bep
August 12, 2016, 7:40am
2
Har to say without seeing what you’re doing, but you have to make sure to pass on the “correct context” to the partial to be able to access the Site.
Fair call - sorry, I should have included some code.
themes/bluejam/layouts/partials/column.html
<div class="blurb"> {{ .Site.Params.description }} </div>
themes/bluejam/layouts/index.html
snip
<div class="four columns"> {{ partial "column.html" }} </div>
snip
config.toml
snip
theme = "bluejam" [params] description = "Some text"
snip
Hopefully that helps?
bep
August 12, 2016, 10:09am
4
You have to pass the context down to the partial.
This is probably what you want:
{{ partial "column.html" . }}
I say probably because it is hard to say without seeing the full picture. Getting the context right is maybe the hardest thing in Go templates. A trick can sometimes be to always use $.
when refering to the outer-most context (page, node, shortcode).
1 Like
Passing down the context down using the extra “.” I missed absolutly fixed the problem. Thankyou bep!