【问题标题】:Hugo cannot convert type page.PagesGroup to PagesHugo 无法将 page.PagesGroup 类型转换为 Pages
【发布时间】:2020-03-09 15:03:27
【问题描述】:

我有一个这样的雨果列表模板:

{{ range (.Paginate (.Data.Pages.GroupByDate "2006")).PageGroups  }}

<h3>{{ .Key }}</h3>
<ul>
    {{ range .Pages.ByWeight }}
    <li>
        <a href="{{ .Permalink }}">{{ if .Draft }}{{ T "draft" }}: {{end}}{{ .Title | markdownify }}</a>
        <time class="date-meta">{{ .Date.Format "Jan 2" }}</time>
    </li>
    {{ end }}
</ul>

{{ end }}

当我像 hugo server -D 这样运行网站时,它运行良好。

当我建立网站时,我得到:

模板执行失败:模板:_default/list.html:15:14:在 <.paginate> 处执行“main”:调用 Paginate 时出错:无法将 page.PagesGroup 类型转换为 Pages

打开调试和详细没有帮助。我有:

content
content/web
content/web/one.md
content/web/two.md
content/web/_index.md
content/web/three.md
content/about
content/about/index.md

什么给了?

【问题讨论】:

    标签: hugo


    【解决方案1】:

    我在编写自定义主题时遇到此错误,但在运行 hugo -Dhugo server -D 时发生。作为一种解决方法,请尝试将其包装在 if 条件中以检查 .Data.Pages

    {{ if .Data.Pages }}
        {{ range (.Paginate (.Data.Pages.GroupByDate "2006")).PageGroups  }}
        ...
        {{ end }}
    {{ end }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多