英文:
Filter Hugo Pagination by Custom Param
问题
更新
参考 Oleg Butuzov 的回答,我可以通过以下方式解决我的第一个问题:
{{ $paginator := .Paginate (where .Site.RegularPages ".Params.yt" ">") 1 }}
但是我遇到了一个新问题,它会列出包含参数 "yt" 的 Hugo 内容文件夹中的所有帖子。然后我在官方 Hugo 论坛的这个帖子中解决了我的问题:https://discourse.gohugo.io/t/complex-where-filter-using-and-or-not/5758/3,来自 @bep 的回复。
接下来,如何使用两个条件对 HUGO 进行过滤:
{{ $paginator := .Paginate (where (where .Site.RegularPages ".Params.yt" ">") ".Params.type" "post") 1 }}
我更新并清理了这个问题,因为很难找到关于这个 Hugo 问题的信息,我希望它也能解决你的问题.. 谢谢
======= 原始问题 ======
如何使用 "where" 过滤变量 $Paginator,只列出包含自定义参数 "yt" 的帖子?
{{ $paginator := .Paginate (where .Site.RegularPages "Type" "post") 2 }}
{{ range $paginator.Pages }}
{{ .Params.yt }}
{{ end }}
{{ template "_internal/pagination.html" . }}
我的 Hugo 模板结构:
conten/Post/
---- post1.md
---- post2.md
theme/layout/post/gameplay.html
然后
post1.md
---
Title: Title 1
type: post
yt: ytchannelid
---
post2.md
---
Title: Tile 2
type: post
---
之前感谢
英文:
UPDATE
refering to Oleg Butuzov answer i can solve my first problem with :
{{ $paginator := .Paginate (where .Site.RegularPages ".Params.yt" ">" "") 1 }}
but i have new problem that its listing all post on content folder Hugo that contain param "yt", and then i solve my problem from Official Hugo Discusion here https://discourse.gohugo.io/t/complex-where-filter-using-and-or-not/5758/3 from @bep reply.
and here.. how to filtering where HUGO with two condition :
{{ $paginator := .Paginate (where (where .Site.RegularPages ".Params.yt" ">" "") ".Params.type" "post") 1 }}
i update and clearing this Question because its realy hard to find about this Hugo Question and i hope its can solve your problem too.. thx
======= ORIGINAL QUESTION ======
how to filter "where" for Variable $Paginator to only listing post that contain Custom param "yt"?
{{ $paginator := .Paginate (where .Site.RegularPages "Type" "post") 2 }}
{{ range $paginator.Pages }}
{{ .Params.yt }}
{{ end }}
{{ template "_internal/pagination.html" . }}
my Hugo Template structure :
conten/Post/
---- post1.md
---- post2.md
theme/layout/post/gameplay.html
then
post1.md
---
Title: Title 1
type: post
yt: ytchannelid
---
post2.md
---
Title: Tile 2
type: post
---
thanks before :)
答案1
得分: 1
你可以使用.Params
和比较运算符的组合。
所以,例如,我想在项目页面上只显示有分支的项目。
{{ define "content" }}
{{ range first 6 (where .Paginator.Pages ".Params.Forks" ">" "") }}
<div class="inner">
<pre>[{{.Params.Forks}}]</pre>
<hr>
</div>
{{ end }}
{{ end }}
- 更多信息请参阅where手册页面。
英文:
You can use combination of .Params
and comparison operators.
So, for example, I want to show the only projects with forks on the project page.
{{ define "content" }}
{{ range first 6 (where .Paginator.Pages ".Params.Forks" ">" "") }}
<div class="inner">
<pre>[{{.Params.Forks}}]</pre>
<hr>
</div>
{{ end }}
{{ end }}
- see more at where manual page.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论