I’m slowly implementing partialCached
on many of my projects.
The variant parameter is great, and I would like to use it in conjuncture with a slice of data.
Per exemple, if a post share the same authors, I want to identify this partial with those two authors.
In this case it’s easy:
{{ partialCached "authors.html" . (string (delimit .Params.authors ""))}}
But in order to use the same trick on a page collection, I have to use scratch and don’t find it ideal.
{{ $novels := where (.Site.RegularPages.RelatedIndices . "novel" ) "Type" "roman" }}
{{ range $novels }}
{{ $.Scratch.Add "novelPartialID" (slice .Params.novel) }}
{{ end }}
{{ $novelPartialID := string (delimit ($.Scratch.Get "novelPartialID") "") }}
The reason behind this .Scratch.Add (slice ..)
+ delimit
hack is Hugo will throw unable to cast []string{"oeuvre"} of type []string to string
if I try to use string
on a string built with .Scratch.Add
.
Anyway, I’M wondering if there is cleaner way to built my partial ID maybe using apply
or something else ? I know, partialCached
can take any number of variants but then again, how to transform a slice into function arguments…
Thanks a ton!