Query Data File / Data Structure Using String

Is there a way to do a data file / data structure query using string? As in something like:

{{ .Site.Data.$device.v1.type }}

I want to replace something the hard-coded selection like:

{{ if eq $device "mobile" }}
    {{ .Site.Data.mobile.v1.type }}
{{ else if eq $device "desktop" }}
    {{ .Site.Data.desktop.v1.type }}
...
{{ end }}

Help needed: I tried to title the problem as close as possible but I don’t think the sentence accurately represents it.

Thanks in adv.

{{ (index .Site.Data $device).v1.type }}
1 Like

Thanks @jmooring! :grin:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.