camp-homepage/gallery/themes/autophugo/layouts/partials/scratch_set_retalbumthumb.html
2023-02-05 13:58:44 +01:00

28 lines
1.0 KiB
HTML

{{- /*
Sets retalbumthumb in .Scratch to the correct albumthumb.
PLEASE NOTE: partials can only get local "dot" . context, they
do not get the global $ context. Therefore, you must get the returned
scratch data from the . context, not from $.
Requires . to be set to the right section.
*/}}
{{- .Scratch.Delete "retalbumthumb" }}
{{- /* If no albumthumb is set, get the first image*/}}
{{- if or (not (isset .Params "albumthumb")) (eq .Params.albumthumb "") }}
{{- with .File }}
{{- $.Scratch.Set "imgglob" (printf "%s" (path.Join .Dir "**")) }}
{{- end }}
{{- $imgglob := default "**" ($.Scratch.Get "imgglob") }}
{{- $imageresources := where (resources.Match $imgglob) "ResourceType" "image" }}
{{- .Scratch.Set "retalbumthumb" (index $imageresources 0) }}
{{- end }}
{{- /* Otherwise get the albumthumb*/}}
{{- with .Params.albumthumb }}
{{- $image := resources.Get . }}
{{- /* The $ here with Scratch means the context outside the with */}}
{{- $.Scratch.Set "retalbumthumb" $image }}
{{- end }}