hugo
I use Hugo to manage this site. It’s pretty cool.
我使用Hugo来管理此网站。 它太酷了。
One thing that got me stuck today was passing 2 parameters to a partial.
今天让我陷入困境的一件事是将2个参数传递给了部分参数。
Since in a partial I could not access .Site.Pages to get the list of pages of the site (due to scope issues), I had to create a dictionary and fill it with 2 items:
由于部分原因我无法访问.Site.Pages来获取网站的页面列表(由于范围问题),因此我必须创建一个词典并将其填充2个项目:
{{ partial "my-partial.html" (dict "context" . "pages" $.Site.Pages) }}
The key here is passing (dict "context" . "pages" $.Site.Pages) as the parameter, instead of . as you usually do with partials.
此处的关键是传递(dict "context" . "pages" $.Site.Pages)作为参数,而不是. 像平常使用局部子一样。
Now inside the partial, instead of using . to access the current context variables you’d use .context.
现在在局部中,而不是使用. 访问当前上下文变量,您可以使用.context 。
And to access the value assigned to pages, I’d use .pages.
要访问分配给pages的值,我将使用.pages 。
You can of course pass multiple items, too. Just add more items to the dict.
您当然也可以传递多个项目。 只需将更多项目添加到dict 。
翻译自: https://flaviocopes.com/hugo-partial-multiple-parameters/
hugo
本文探讨了在Hugo静态站点生成器中如何有效地向部分模板传递多个参数,解决了因作用域限制无法直接访问.Site.Pages的问题。通过创建并填充字典,可以灵活地在部分模板中使用.context访问上下文变量,以及使用.pages访问页面列表。

2058

被折叠的 条评论
为什么被折叠?



