Hi All,
I would like your thoughs on one thing.
In my hugo.toml
file I got specified few parameters, each parameter with three values.
I am calling this parameters to be used in layout using shortcode. In frontmatter of each post I specify only the ones that need to be displayed.
The issue I have right now is that Order, in which items are taken and displayed is strictly as placed in hugo.toml
file.
Can I ask for help with keeping an order as specified in frontmatter?
Thats about what I like to get help with, now a bit of examples.
The frontmatter for post (example here) contains:
amazon:
- Blender
- IrishGlass
- IceCreamScoop
hugo.toml
contain something like that in relation to this three elements.
[[params.amazon]]
identifier = "IceCreamScoop"
picture = "/amazon/Ice_Cream_Scoop.jpg"
path = "https://amzn.to/4dmx6nv"
[[params.amazon]]
identifier = "Blender"
picture = "/amazon/Blender.jpg"
path = "https://amzn.to/3vBuaCE"
[[params.amazon]]
identifier = "IrishGlass"
picture = "/amazon/Irish_Glass.jpg"
path = "https://amzn.to/4c5zFZs"
The shortcodde (which I am using inside content {{< amazon >}}
) code is as follow (part):
{{ $allTools := .Site.Params.amazon }}
{{ $frontmatterIds := $.Page.Params.amazon }}
{{ with $frontmatterIds }}
<div id="amazon-slider">
<div class="amazon-container" id="scroll-container">
{{ range where $allTools "identifier" "in" . }}
{{ $toolPicture := resources.Get .picture }}
<div class="amz">
<picture class="amazon-image" aria-labelledby="{{ printf "figcaption-%s" ($toolPicture.RelPermalink | hash.XxHash) }}">
<a href="{{ .path }}" target="_blank" rel="noopener">
{{- $200w := $toolPicture.Resize "200x webp" -}}
{{- $400w := $toolPicture.Resize "400x webp" -}}
<source srcset="{{with $400w.RelPermalink }}{{.}}{{ end }} 2x,
{{with $200w.RelPermalink }}{{.}}{{ end }}"
type="image/webp">
<img src="{{ $toolPicture.RelPermalink }}" alt="{{ T .identifier }}" width="200" height="200" decoding="async" loading="lazy"/>
<span id="{{ printf "figcaption-%s" ($toolPicture.RelPermalink | hash.XxHash) }}" class="caption">{{ T .identifier }}</span>
</a>
</pictire>
</div>
{{ end }}
</div>
</div>
{{ end }}
This will render in order from hugo.toml
file like that:
- IceCreamScoop
- Blender
- IrishGlass
because thats the order in that file.
Can I ask for advise/help how to request order as per statement in contant file?
In this need, will be:
- Blender
- IrishGlass
- IceCreamScoop