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