I need for
loop in template.
for i := start; i < finish; i++ {
// do something
}
Is it just one way by using range
with prepared array or how can I add this functional to templates?
I need for
loop in template.
for i := start; i < finish; i++ {
// do something
}
Is it just one way by using range
with prepared array or how can I add this functional to templates?
The simplest way is probably to use range
and an external function. For example (On play):
func For(start, end int) <-chan int {
c := make(chan int)
go func() {
for i := start; i < end; i++ {
c <- i
}
close(c)
}()
return c
}
in the template:
{{range For 0 10}}
i: {{.}}
{{end}}