go - How to get the index of range in Beego's template file -
for example
{{ range .cars }} {{.color}} , ${{.price}} {{ end }} the array size of 'cars' 10. how index value?
when index 5, want process.
i using beego web framework.
first of all, reply question given in comment topskip.
range $index, $element := pipeline see documentation @ golang.org/pkg/text/template/#hdr-variables.
secondly, bear in mind templates rapidly complex when start putting logic in, such treating 5th element differently.
with in mind, thought instead seek design view models simple render. more logic might needed in controllers, it's easier test there. alternatively, consider using helper utilities written in go.
less logic in templates create things easier.
go
No comments:
Post a Comment