Hugo: tpl: Extend "where" to iterate over maps

Created on 29 Mar 2016  路  3Comments  路  Source: gohugoio/hugo

Hugo can't resolve the following template construct since the starting sequence is a map:

{{ range where .Site.Data.person "name" "Victor Hugo" }}

Extend where to iterate over maps.

See Tutorial: Link .Site.Data to Content Types by Filename discussion.

Enhancement

Most helpful comment

+1 from me, I just ran into the exact same problem.

FWIW, this is what I ended up with, I'd be interested to know if there was something more elegant:

{{ $people := slice }}
{{ range .Site.Data.people }}{{ $people = $people | append . }}{{ end }}
{{ range where $people "name" "Victor Hugo" }}
  {{ .twitter_handle }}
{{ end }}

All 3 comments

Is that even correct syntax? Shouldn't it be

{{ range where .Site.Data.person ".name" "eq" "Victor Hugo" }}

I believe where defaults to eq if not present.

+1 from me, I just ran into the exact same problem.

FWIW, this is what I ended up with, I'd be interested to know if there was something more elegant:

{{ $people := slice }}
{{ range .Site.Data.people }}{{ $people = $people | append . }}{{ end }}
{{ range where $people "name" "Victor Hugo" }}
  {{ .twitter_handle }}
{{ end }}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bep picture bep  路  3Comments

antifuchs picture antifuchs  路  3Comments

ianbrandt picture ianbrandt  路  3Comments

digitalcraftsman picture digitalcraftsman  路  3Comments

mariusa picture mariusa  路  3Comments