Is it possible to define a page resource, but which points to a file that is already referenced by another resource of the same page?
I have several image resources (image_*
) on each page, and usually a separate file for header image resource (header_image
). Sometimes however I want to use an existing resource as the header image. I already tried the following:
resources:
- name: header_image
params:
alt: "Alternate text."
src: image-1.webp
- name: image_1
params:
alt: "Alternate text."
src: image-1.webp
- name: image_2
params:
alt: "Alternate text."
src: image-2.webp
But Hugo only displays the first reference to image-1.webp
, which in this case is the header_image
and if the resources order is reversed, it will only display image_1
. So, if two resources referencing (via src
) the same file are accessed, only one that is declared as first seems to be available.
I’m accessing resources in various parts of my theme with GetMatch
and Match
statements. For example:
{{ with .Resources.GetMatch "header_image" }}
<section class="page-heading heading-portfolio" style="background-image: url({{ .RelPermalink }}); background-position: {{ $headerpos }}; background-size: cover;">
{{- end }}
And:
{{ $image_count := .Resources.Match "image_*" | len }}
{{ range .Resources.Match "image_*" }}
<a href="{{ .RelPermalink }}">
{{ if gt $image_count 1 }}
{{ with .Resize "640x" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }} height="{{ .Height }} alt="{{ .Params.alt }}">
{{ end }}
{{ else }}
{{ with .Resize "1280x" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }} height="{{ .Height }} alt="{{ .Params.alt }}">
{{ end }}
{{ end }}
</a>
{{ end }}
I’m aware of “the order matters” rule mentioned in the docs, but I’m not sure if it might be the culprit of my problem.
Could someone please shed some light on this matter?