just FYI, I also tried putting {{ .Param “has_code” }} in my head.html, which did not display true, whereas putting the same code within the body of my index.html does display proper output.
I also saw another post that suggested {{ partial “head.html” $. }} instead of {{ partial "head.html . }} to get param to pass to partial but with 0.18.1 I get error: “unexpected <.> in operand”
Finally, I also tried removing the underscore in my param name… and also tried this with older 0.17 no luck. Running 64bit linux installed from .deb package.
So, this morning, I immediately realized what the actual problem is but not sure how to resolve it. I’m hoping this reply will “help you help me.”
Down in the body of my home page template (index.html), I have a range loop that allows my to only display the most recent non-draft “article” on the page:
{{ range first 1 (where (where .Site.Pages “Section” “articles”) “Draft” false) }}
… HTML to display the article’s title, content, etc. …
{{ end }}
Is there a way to pass the site page params from this range result back up to the head.html partial? I’m guessing the answer is no. Is there a workaround?
My intention was to have my head.html partial evaluate the “hasCode” and add a script tag to include, if true:
{{ $hascode := .Params.hascode }}
{{ if eq “true” $hascode }}
…script type=“text/javascript” src=’{{ .Site.BaseURL }}/js/hascode.js"…
{{ else }}
(do nothing)
{{ end }}
Any ideas?
Regards, and thanks for Hugo! I’m really enjoying the experience of wrapping my head around this awesome tool.
I am guessing my only solution is to move my range loop to the top of the template, then do a map and pass everything down to the partial and the rest of the document. Before sleep, I tried doing a map and I guess I just thought it would magically pick up the page params from the loop, appearing later in the template, then pass them back up to where I included my partial.
Turns out that putting my range loop at the top of my document and simply putting {{ partial “head.html” . }} inside the loop resolved, solving one problem to create another.