【问题标题】:In a Hugo partial template, how do I access secondary/additional parameters?在 Hugo 部分模板中,如何访问辅助/附加参数?
【发布时间】:2018-02-08 08:01:26
【问题描述】:

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

有了这个,我可以访问第一个参数或$test,只需在li.html 模板中引用.,但我如何从同一个模板?

【问题讨论】:

标签: go go-templates hugo


【解决方案1】:

我建议使用 hugo dict 功能。它允许您使用键/值对来传递信息。 documentation 声明适用于您的用例。

{{ partial "yourPartial" (dict "test" "yourTestData" "term" "yourTerm") }}

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 2015-12-04
    • 1970-01-01
    相关资源
    最近更新 更多