Hello,
i’m trying to get the variable $pix_counter
outside the range {{ range .Params.photo }}
.
The objective is to change the thumbnailWidth
in relation to the number of photos in my .Params.photo
I have read the docs over and over and dozens of topics on the forum (i’m french so i may have missed something). I understood that the key is the .Scratch
thing i have try many things : .Scratch.Set
, .Scratch.Get
,.Scratch.Add
But nothing works, i’m going to be crazy.
If someone can help me to figured this out that would be really kind
Here is my partial code source
<div class="micro-box">
{{ if isset .Params "photo" }}
{{ $pix_counter := 0 }}
{{ range .Params.photo }}
{{ $pix_counter = add $pix_counter 1 }}
{{/* The .Scratch.Set stuff must be here i presume */}}
{{ end }}
<div id="nanogallery_{{ with .File }}{{ .ContentBaseName }}{{ end }}" data-nanogallery2='{
{{/* And the .Scratch.Get stuff must be here i presume */}}t
{{ if $pix_counter eq 1 }}
"thumbnailWidth": "800",
{{ else if $pix_counter eq 2 }}
"thumbnailWidth": "400",
{{ else if $pix_counter ge 3 }}
"thumbnailWidth": "200",
{{ end }}
"thumbnailHeight": "auto",
"locationHash": "true",
"allowHTMLinData": "true"
}'>
{{ range .Params.photo }}
{{ $media_base_url := "https://media.jeer.fr/" }}
{{ $media_filename := strings.TrimPrefix $media_base_url . }}
<a href="{{ . }}" class="u-photo">{{ $my_title }}</a>
{{ end }}
</div>
{{ end }}
</div>
Thank You