Range pages by passed params doesn't work

Hi guys, I just want something like that:
1- I have a grid news section
2 - want to include the news section in index page, and pass it some array of categories, so it will fetch posts from the passed categories.
But if my partial section has already range query, it doesn’t work.

index.html

{{ partial "spotlight" (dict "categories" "spotlight" ) }}

partial.html

{{ range .Site.Pages ("Sections" "posts" "Params.categories" "spotlight") }}

how to write the correct query? I want to pass 2 or more categories slugs. thanks.
It display blank results

index.html

{{ partial "spotlight.html" (slice "cat-a" "cat-b") }}

layouts/partials/spotlight.html

{{ range where (where site.RegularPages "Section" "posts") "Params.categories" "intersect" . }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

Yes it works, but if i’d like to fetch the latest 5 by date desc? thanks

{{ range (where (where site.RegularPages "Section" "posts") "Params.categories" "intersect" .).ByDate.Reverse | first 5 }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
1 Like

Thank you very much :smiley: one more question, in some partials i have static category name, i tried like that but doesn’t work (have around 10 posts with that category):

"Params.categories" "my-cat"

Always treat taxonomies as a slice, even if there’s only one value.

ah ok, so if i include a partial file, need to add everytime dict slice()?

The “spotlight” partial that I defined above expects its context to be a slice.

If you have further questions please open a new topic.

for example, i have a partial file called related articles, so i’d want to fetch some articles that have the same post categories, (when user is on post page)
how i can pass them? (slice .Page.categories) ?

See my previous comment: