Range to build a variable

How do I write this :

srcset="{{ range uniq (slice $medium $small $very_small $smallest ) }} {{ .Permalink }} {{.Width}}w,{{end}}"

But trimming the last , ? I don’t see how to use range to build a variable, then trim it.
Thanks.

Perhaps delimit helps. Or chopping of the last comma with replaceRE.

{{ $src := slice }}
{{ range uniq (slice $medium $small $very_small $smallest) }}
  {{ $src = $src | append (printf "%s %dw" .Permalink .Width) }}
{{ end }}
<img srcset="{{ delimit $src `, ` }}" />

Thanks.

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