hugo_如何在Hugo中将多个参数传递给局部

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值