Add example to index function (#1536)

This commit is contained in:
Joe Mooring 2021-10-11 08:26:55 -07:00 committed by GitHub
parent e3dd8c5077
commit 6a5b29fcc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,14 @@ The function takes multiple indices as arguments, and this can be used to get ne
{{ index $map "c" "e" }} => 20
```
You may write multiple indices as a slice:
```go-text-template
{{ $map := dict "a" 100 "b" 200 "c" (dict "d" 10 "e" 20) }}
{{ $slice := slice "c" "e" }}
{{ index $map $slice }} => 20
```
## Example: Load Data from a Path Based on Front Matter Params
Assume you want to add a `location = ""` field to your front matter for every article written in `content/vacations/`. You want to use this field to populate information about the location at the bottom of the article in your `single.html` template. You also have a directory in `data/locations/` that looks like the following: