Reputation: 1549
I'm converting an erb template to a Go template (using Hugo), and I'm trying to create a specific number of identical <div>
s. Ruby has the times iterator, which worked well in the erb template. I assume there's something similar in Go, but I'm having a hard time finding it.
in Erb:
<% 100.times.each do |i| %>
<div class='star'></div>
<% end %>
I see that Go templates allow to iterate over a collection using range
, but it's unclear how to do the above in a Go template without explicitly creating a collection with 100 items.
This question has some information on iterating a specific number of times in Go, but is not in the context of Go templates: Is there a way to iterate over a range of integers in Golang?
Upvotes: 5
Views: 3348