Show posts by category not working

I’m creating posts by category. But I found one problem. I use the code below to display posts based on the desired category. But this code is not working and why ?

{{ $category := .Scratch.Get "category" }}
{{ range $i, $item := first 5 (where .Site.RegularPages  ".Params.category" "in" $category) }}
//content summary
{{ end }}

I tried using this code for other cases but the same, but the code below works instead.

{{ range $i, $item := first 5 (where .Site.RegularPages  ".Params.featuredPost" "=" true) }}
//content summary
{{ end }}

Please, help me to solve this problem.Thanks!

Assuming that $category is a string…

{{ range $i, $item := first 5 (where .Site.RegularPages  "Params.categories" "intersect" (slice $category)) }}
2 Likes

Thanks, now i can passing data to partials and create post by category :grinning:

{{ .Scratch.Set "category" "Hugo" }}
{{ partial "widget/post-by-category.html" . }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.