When I print {{ $.Site.Data.products }} it gives me this: [map[products:[map[name:Snickers price:39] map[name:Twix price:11] map[name:Mars price:11] map[name:Milky Way price:11]]]]
I tried:
{{ $data := $.Site.Data.products }}
{{ range $data }}
{{ range where .products .name "=" .Name }}
{{ .price }}
{{ end }}
{{ end }}
I do not know what you’re trying to do. What you are trying to do?
if you have /data/products.json as you have pasted, then
{{ $name := "Twix"}} <!--You can set `{{/* $name := .Name */}}` ... OR look below-->
{{ range (.Site.Data.products) }}
{{ range .products }}
{{ if eq .name $name}} <!-- {{/* if eq .name .Name */}} You can do this too -->
Name : {{ .name }}<br>
Price: {{ .price }}
{{ end }}
{{ end }}
{{ end}}
Are you sure this is the format of your json file? Also what is its name?
because if it lives at data/products.json as it stands you will have to dig through this array of objects to find your products… (products[0].products)
Something like:
{{ $name := .Params.product_name }}
{{ with index site.Data.products 0 }}
{{ with where .products "Name" $name }}
{{ range . }}
{{ .price }}
{{ end }}
{{ end }}
{{ end }}