I’m getting to grips with hugo, having never before used a static website generator. It seems very nice.
I’m using hugo v0.13.
I have a use case (common?) where I want to have a collection of variables defined in a data file /data/myfile.yaml whose values I can insert by name as needed into various content files. (In my use case these represent calendar dates that get updated every year). For example:
startdate: 13 Jan 2015
enddata: 30 Jun 2015
I think what I need is to define a shortcode named getdata with a single positional parameter.
Inside a content file this would be used set to the name of the data variable I want to insert:
## content file use case
Start date is {{%getdata startdata%}}, end date is {{%getdata enddata%}}
The shortcode defined as file getdata.html in /layout/shortcodes would then be:
{{.Data.myfile.{{.Get 0}}}}
Here the inner {{}} are needed to access the value of the shortcode parameter, and the outer {{}} are needed to access the value of the desired variable .Data.myfile.startdata or .Data.myfile.enddata
Is this type of expansion possible? I’m unclear the exact semantics of variables inside shortcodes and reckon if I try to do this by trial and error it will take a long time.
Also: are the names here case sensitive? I’m not at the moment quite sure when a capitalised first letter is required: .Data and when not .myfile, or anything defined under .Params (seems to be a change in v0.13)?
Thanks very much for bearing with what is an uninformed question.
Trying to do something similar, I have a YAML file in /data/ that I generate a table from. We want to use a shortcode in markdown to create the table, and pass a specific yaml key to the shortcode so it knows what data file to use.
Using the example above, I get this:
ERROR: 2015/04/23 error processing shortcode shortcodes/providerTable.html
ERR: template: shortcodes/providerTable.html:8:22: executing “shortcodes/providerTable.html” at <.Page.Site.Data…>: systemProviders is not a method but has arguments
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.