hugo - Hugo 无法将 page.PagesGroup 类型转换为 Pages
问题描述
我有一个这样的雨果列表模板:
{{ 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”:调用分页时出错:无法将 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 -D
或hugo server -D
. 作为一种解决方法,尝试将其包装在一个if
条件中以检查.Data.Pages
.
{{ if .Data.Pages }}
{{ range (.Paginate (.Data.Pages.GroupByDate "2006")).PageGroups }}
...
{{ end }}
{{ end }}
推荐阅读
- java - 出于好奇,是否可以初始化一个 0×1 数组?
- firefox-addon - 如何使用承诺和回调将 chrome 扩展移植到 Firefox 插件
- vbscript - 如何在 VBScript 中返回 ArrayList?
- python - 在列表中查找特定字符
- css - DIV/SPAN 标签未在 GRID 的最后一个完整显示
- spring-boot - 如何将 ConstraintViolationException 500 错误转换为 400 错误请求?
- python - Compare two dictionaries returned from REST framework using pytest
- postgresql - 如何通过层次结构连接加入同一张表?
- php - 为什么不保存到数据库,excel导入
- javascript - Ag-Grid setRowData 没有设置网格内的数据