雨果:.Data.Pages在Blog.html上下文中有效,但在另一个上下文中失败

时间:2018-08-11 07:29:19

标签: hugo

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:无法遍历

注释:

    使用以下命令直接从index.html调用
  • blog部分: {{ partial "blog" . }}
  • 漫画部分是通过jumbotron.html从索引html间接调用的 index.html: {{ 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数据引用此变量,但是它不起作用。 任何帮助将不胜感激。

0 个答案:

没有答案