【发布时间】:2022-06-11 05:56:54
【问题描述】:
在雨果模板中,我如何查找.Site.Data。假设我有这样的数据结构:
{
"my-blog-post": {
"Version": 21,
"Revision": 0,
"Code": "my-blog-post",
"Name": "My Blog Post",
"Parent": "the-parent-post"
},
"another-post": {
"Version": 21,
"Revision": 0,
"Code": "another-post",
"Name": "Another Post",
"Parent": "the-parent-post"
}
}
在博客文章的详细信息页面中,我想获取以当前文章为父级的所有文章的列表。基本上我想查询以“父帖子”作为父字段值的帖子。 我可以使用 range 来实现这一点,但我需要让它们使用 where。 我尝试过这样的表达方式,但没有任何乐趣。
{{$child_posts := where (where .Site.Data "Section" "blog") "Parent" "the-parent-post" }}
我可以这样做:
{{$posts := where $site.Pages "Section" "blog"}}
{{ range sort $posts "Name" "asc" }}
{{ $post := . }}
{{if eq $post.parent $currentPage.Code}}
...Do something...
{{end}}
{{end}}
但这并不理想,也不是我需要的。 提前致谢。
【问题讨论】:
标签: hugo