How to index a slice element?

DeanSinaean picture DeanSinaean · Oct 3, 2012 · Viewed 29.4k times · Source

I have a slice: Keys []* datastore.Key

How could I index one of them in the template file? I guessed {{.Keys[3] }}, but that doesn't work and I searched a lot but with no clue.

Any suggestions would be welcome, thanks.

Answer

nemo picture nemo · Oct 3, 2012

Use the index command like so:

{{index .Keys 3}}