mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-10-05 14:31:14 -04:00
921 B
921 B
title | linktitle | description | godocref | date | publishdate | lastmod | categories | tags | signature | workson | hugoversion | relatedfuncs | deprecated | aliases | needsexample | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
index | index | Looks up the index(es) or key(s) of the data structure passed into it. | https://golang.org/pkg/text/template/#hdr-Functions | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
false | true |
index
looks up the index(es) or key(s) of the data structure passed into it.
From the godocs:
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.
In Go templates, you can't access array, slice, or map elements directly the same way you would in Go. For example, $.Site.Data.authors[.Params.authorkey]
isn't supported syntax.
Instead, you have to use index
, a function that handles the lookup for you.