How do you write this function. I would love to put in a comma in between tags but not at the last tag item.
So say you have two tags = tag1,tag2.
if you have just one tag the comma shouldn’t come up.
I tried this but doesn’t work.
{{$num_tags = len .Params.tags}}
{{range .Params.tags}}
<a>{{.}}</a>{{if ge $num_tags 2}},{{end}}
{{end}}
@ddanawoski Not sure which of us you were replying to, but I think I figured out what you mean. I think both Joe and I were following your code to closely. What I think you’re looking for is this:
{{ range $i, $e := .Params.tags }}{{ if $i }}, {{ end }}{{ printf "<a href=\"/%s\">%s</a>" $e $e }}{{ end }}
except there is likely a better way to do the “/%s” and probably this could be done with delimit + apply, but I’ll let @jmooring handle that as I’m not used to the apply function, and he’s far better with Hugo than I am in any event.