0
{{ range .foo }}
                
{{end}}

.

{{range $index, $element := .foo }}

{{end}}

I'm aware that you can use this like for loop, but is there any other way to access a value in array directly like {{ foo[2] }} in Revel Template? I've read this Revel documentation but doesn't seem to find any.

Michael Halim
  • 262
  • 2
  • 20
  • You can use the function `index`: *"Returns the result of indexing its first argument by the following arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array."* – mkopriva Sep 16 '22 at 03:16

1 Answers1

2

It is not Revel specific, indexing is included in the standard library templates:

{{index .foo 2}}

Burak Serdar
  • 46,455
  • 3
  • 40
  • 59