I am trying to make a shortcode that pulls in related pages based on a list of topics.
I have related pages working elsewhere in the site, but this is tricky because it is from a specific list using .RelatedTo
.
The shortcode is
{{< list-resources topics="design, content" >}}
It works if I hard code in the topics into the keyVals
, like this:
# Gets the list of $related_pages based on the topics
{{- $related_pages := $.Site.RegularPages.RelatedTo ( keyVals "topics" "design" "content") -}}
# Passes this data to the list_related_resources partial that will make the list
{{ partial "core/list_related_resources.html" (dict "Page" .Page "RelatedPages" $related_pages) }}
But if I try to pass the array (slice) to the KeyVals
, I get 0 $related_pages pages.
# Gets the list of topics passed through the shortcode
{{- $topics := (slice (.Get "topics")) -}}
# Gets the list of $related_pages based on the topics
{{- $related_pages := $.Site.RegularPages.RelatedTo ( keyVals "topics" "design" "content") -}}
# Passes this data to the list_related_resources partial that will make the list
{{ partial "core/list_related_resources.html" (dict "Page" .Page "RelatedPages" $related_pages) }}
Any thoughts?