It’s easy enough to get a resource title (say $a_res.Title
), but what if I want to arbitrarily define the resource attribute I need as a string, in say data/my_keys.yaml
e.g. ".Title"
, ".Params.weight"
, ".Params.group"
, etc? One of several reasons being: non-technical users have an easier time defining strings rather than editing go templates.
The first thing that comes to mind is to just use index
(e.g. index $a_res ".Title"
), but that returns an error: error calling index: can't index item of type resources.resourceAdapter
.
Any ideas?
<!-- A resource -->
{{ $a_res := (index .Resources 0) }}
{{ $my_key := ".Title" }}
<!-- Works! -->
{{ $a_res.Params.weight }}
{{ $a_res.Params.group }}
{{ $a_res.Title }}
<!-- Doesn't work: "error calling index: can't index item of type resources.resourceAdapter" -->
{{ index $a_res ".Params.weight" }}
{{ index $a_res ".Params.group" }}
{{ index $a_res ".Title" }}
<!-- Doesn't work: "error calling index: can't index item of type resources.resourceAdapter" -->
{{ index $a_res $my_key }}