Say I have {{ partial "li.html" $test $root.Data.Term }}
.
With this I can can access the first parameter, or $test
, by simply refering to .
within the li.html
template, but how do I access the second or additional parameter ($root.Data.Term
) from within the same template?
Partials are smaller, context-aware components in your list and page templates that can be used economically to keep your templating DRY.
Template partials are small bits of reusable template or tag parts. You could create a Template partial for any number of purposes, anywhere that you need to reuse a small portion of a template, including partial or complete tags, other variables, etc.
Partials often refers to HTML that is not a complete web page, but is intended for re-use within multiple web pages. Common examples are the header and the footer of site pages.
I would suggest using the hugo dict function. It allows you to use key/value pairs to pass information. The documentation states that for your use case.
{{ partial "yourPartial" (dict "test" "yourTestData" "term" "yourTerm") }}
You can then access the values by just using {{ .test }} and {{ .term }}.
Alternatively you can use the scratch function, which is a more "global" approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With