在 Hugo 部分模板中,如何访问辅助/附加参数?

01A*_*key 9 go go-templates hugo

说我有{{ partial "li.html" $test $root.Data.Term }}

有了这个,我可以访问第一个参数,或者$test,通过简单地.li.html模板中引用,但是如何$root.Data.Term从同一个模板中访问第二个或附加参数 ( )?

Boe*_*rsi 14

我建议使用 Hugo dict函数。它允许您使用键/值对来传递信息。该文件指出,对于你的使用情况。

{{ partial "yourPartial" (dict "test" "yourTestData" "term" "yourTerm") }}
Run Code Online (Sandbox Code Playgroud)

然后,您只需使用{{ .test }}{{ .term }}即可访问这些值。

或者,您可以使用Scratch函数,这是一种更“全局”的方法。