Example: load data from a path based on front matter parameters
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:
The content of oslo.toml can be accessed from your template using the following node path: .Site.Data.locations.oslo. However, the specific file you need is going to change according to the front matter.
This is where the index function is needed. index takes 2 arguments in this use case:
The node path
A string corresponding to the desired data; e.g.—
The variable for .Params.location is a string and can therefore replace oslo in the example above:
Now the call will return the specific file according to the location specified in the content’s front matter, but you will likely want to write specific properties to the template. You can do this by continuing down the node path via dot notation (.):