I have code that works (!) but am looking for someone with more experience templating for any advice on something more elegant.
I’m looking to generate links to a partial and static asset files (CSS & JS) that are based on a front matter variable - in my case it’s a number.
I set each piece of content to have a number (day = "01"
for example), and it grabs CSS & JS files per content and pulls them in.
<link rel="stylesheet" href="{{ (delimit (slice "css/day" .Params.Day ".css") "") | absURL }}" type="text/css" />
And then do the same for a partial call:
{{ partial (string (delimit (slice "demo/day" .Params.Day ".html") "")) . }}
This was based on my understanding (and trial and error) from the documentation:
- Slice seems to create spaces between things squashed together, so it needed
delimit
with an empty string to remove them - Use absURL to ensure file path is correct, as site is sitting in a sub-folder
- Need to make it a string for the partial call to work
Is this the best way to achieve this, or is there a better / more efficient solution? Something feels off/unnecessary with what I’ve done. Many thanks.