Adding a specific attribute to an image

I would like to add loading="lazy" to only the images after the first image in the code example below. Is this possible? Right now, I am duplicating the chunks of code to achieve the same (range first 1 $latestPages and range after 1 $latestPages| limit 2 and applying the attribute to the later).

 {{- range first 3 $latestPages }}
<!-- content goes here (title, meta) -->
<img src="" loading="lazy"> <!-- loading attribute for only the last two images of the three -->
{{- end }}

I found this range $k, $v thing. Brilliant!

{{- range $k, $v :=  $latestPages | first 3 }}
<!-- content goes here (title, meta) -->
{{- if not $k }}
<img src="">
{{- else }}
<img src="" loading="lazy">
{{- end }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.