hugoDocs/content/functions/index-function.md
2017-02-26 22:23:06 -06:00

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
functions
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.