在 blog.html 部分中,我有:
{{ range first 1 (where .Data.Pages "Type" "post") }}
<div class="ph1-ns w-50-ns flex">
{{ .Render "li" }}
</div>
{{ end }}
成功获取了一篇博客文章的数据。
我还有另一个完全相同的部分 comic.html :
{{ range first 1 (where .Data.Pages "Type" "post") }}
<div class="ph1-ns w-50-ns flex">
{{ .Render "li" }}
</div>
{{ end }}
但这失败并显示以下消息:
2:18:57 PM:错误2018/08/11 04:18:57渲染“部分”时出错:模板:/opt/build/repo/site/layouts/section/products.html:3:3 :在
处执行“ main”:错误:调用partial:模板:partials / jumbotron.html:6:11:在 处执行“ partials / comic.html”:错误调用where:无法遍历 >
注释:
{{ partial "blog" . }}
{{ partial "jumbotron" (dict "imageUrl" .Params.image "title" .Title "subtitle") }}
jumbotron.html:
{{ partial "comic" . }}
我怀疑这可能是由于未将上下文传递给jumbotron引起的,因此在jumbotron.html中尝试过:
{{ partial "jumbotron" (dict "imageUrl" .Params.image "title" .Title "subtitle" .Params.subtitle "content" .) }}
,然后使用.content
撤消该上下文,即
{{ range first 1 (where .content.Data.Pages "Type" "post") }}
但是这也不起作用。我什至尝试使用.Site.GetPage
声明变量
然后为.Data.Pages数据引用此变量,但是它不起作用。 任何帮助将不胜感激。