In content > products
, I have a list of content files, and an image folder (headless = true
) where I store my product images.
The following code finds all images successfully:
{{$productImages := ($.Site.GetPage "/products/images").Resources}}
{{$productImages := $productImages.GetMatch (printf "%s.*" (anchorize .Title))}}
{{with $productImages}}
...
{{end}}
This works, because all images are named the same as each content file .Title
.
I would like to shorten the image files names. Instead of product-1-made-in-nyc-by-company-a.jpg
, I would change it to product-1.jpg
. Each image name will be unique and have the same beginning as the content file .Title
, just truncated.
When I change the image name, I can no longer get the code snippet to work. No images appear. I’ve tried changing the statement to include a wildcard, but that doesn’t work.
{{$productImages := $productImages.GetMatch (printf "%s*.*" (anchorize .Title))}}
Any ideas on how I can use GetMatch
to match part of the .Title
? Thanks!