按自定义参数筛选 Hugo 分页

huangapple go评论93阅读模式
英文:

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 问题的信息,我希望它也能解决你的问题.. 谢谢 按自定义参数筛选 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
---

之前感谢 按自定义参数筛选 Hugo 分页

英文:

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 按自定义参数筛选 Hugo 分页

======= 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 &quot;content&quot; }}
  {{ range first 6 (where .Paginator.Pages &quot;.Params.Forks&quot; &quot;&gt;&quot; &quot;&quot;) }}
    &lt;div class=&quot;inner&quot;&gt;
    &lt;pre&gt;[{{.Params.Forks}}]&lt;/pre&gt;
    &lt;hr&gt;
    &lt;/div&gt;
  {{ end }}
{{ end }}
  • see more at where manual page.

huangapple
  • 本文由 发表于 2021年8月3日 16:10:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/68632489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定