[delimit function]: Unable to generate a delimited string of Image Resource Permalinks

I am unable to generate a string containing the comma separated permalinks of several image resources and I cannot figure out why the delimit function does not work in this case:

{{- with .Resources.ByType "image" -}}
   <g:additional_image_link>
      {{- range first 4 (after 1 .) -}}
         {{- $original := . -}}
         {{- $thumb := ($original.Fill "1080x1080").Permalink -}}
            {{- delimit (slice $thumb) "," }}
      {{- end -}}
   </g:additional_image_link>
{{- end }}

Desired output:

<g:additional_image_link>https://www.example.com/img/002_<hash>_q75_box_smart1.jpg,https://www.example.com/img/003_<hash>_q75_box_smart1.jpg</g:additional_image_link>

Hugo output:

<g:additional_image_link>https://www.example.com/img/002_<hash>_q75_box_smart1.jpghttps://www.example.com/img/003_<hash>_q75_box_smart1.jpg</g:additional_image_link>
{{- $thumb := ($original.Fill "1080x1080").Permalink -}}
{{- delimit (slice $thumb) "," }}

$thumb only contains one element for each range loop iteration, so thats why it wont produces delimited element.


The delimit function should be outside the range loop and you need to store all .Permalink first.

{{- with .Resources.ByType "image" -}}
      {{- $thumb := slice -}}
      {{- range first 4 (after 1 .) -}}
         {{- $original := . -}}
         {{- $thumbPermalink := ($original.Fill "1080x1080").Permalink -}}
         {{- $thumb = $thumb | append $thumbPermalink -}}  
      {{- end -}}
<g:additional_image_link>
{{- delimit $thumb "," }}
 </g:additional_image_link>
{{- end }}
3 Likes

Ah! Thanks so much @pamubay :four_leaf_clover:

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