In the assets folder (I am creating a products section for a site, and I was advised using a data file is better, rather than page bundles for scalability).
I would approach this by organizing images by SKU, eliminating the need to specify image paths in front matter. I think this would be much easier to maintain.
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ with resources.GetMatch (printf "images/%s/%s/featured.*" .Section .Params.sku) }}
{{ with .Resize "300x" }}
<div class="image image-featured">
<img src="{{ .RelPermalink }}" alt="{{ $.Title }} featured image">
</div>
{{ end }}
{{ end }}
{{ range resources.Match (printf "images/%s/%s/*.*" .Section .Params.sku) }}
{{ if not (in .Name "featured") }}
{{ with .Resize "300x" }}
<div class="image">
<img src="{{ .RelPermalink }}" alt="{{ $.Title }}">
</div>
{{ end }}
{{ end }}
{{ end }}
{{ .Content }}
{{ end }}
Notes:
In your data file, use an array for your categories, even if thereβs only one category.
Always use lower case when naming directories and files.
The non-featured images will be ordered by filename. You can name them however youβd like, but I would prefix with something like β01β to control the rendering order.
Try it:
git clone --single-branch -b hugo-forum-topic-51724 https://github.com/jmooring/hugo-testing hugo-forum-topic-51724
cd hugo-forum-topic-51724
hugo server
Remember that you can include markdown files in the products directory, and they will be merged with the pages created by the content adapter to form the page collection. This could be used to temporarily add a product to the site until you have time to update the data file.
I donβt have enough words to thank you for this solution. I took time to study it and I was able to include it in my own design, including adding the featured image in the list page.
This ByParam | Hugo was also handy since I wanted to show the products by price in ascending order on the product page.