In a Hugo partial template, how do I access secondary/additional parameters?

4.1k views Asked by At

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?

1

There are 1 answers

0
Boehrsi On BEST ANSWER

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.