Using where() with maps and not arrays?

Hi everyone,
I wonder if there’s any possibility to use the where function on map data type and not lists/arrays?

For example, my data files structure is something like:

├── data
│   ├── events
│   │   ├── 2015chicago.yml
│   │   ├── 2015warsaw.yml
│   │   └── 2016kiel.yml

and each file looks like:

status = [past|current]  # that's past or current

From the looks of it, I cannot run something like:
{{ range where $.Site.data.events "status" "past" }} since {{ range $.Site.data.events }} is actually a map type (map[filename][content]).
The only way I see to do what I want right now is to actually merge all these data files into one event.yml that contain an array instead of a dict.

Is there any other way to do what I want?

2 Likes

@tatsushid would know, but I assume currently not possible. But it would be fairly easy to extend the where func with map support if we could agree on what to do about the sorting (as is (fairly random) or sort by key?)

Yea, I think going by key is the usual convention (since value can be complex data type).
Python:

In [2]: x = [1,2,3]

In [3]: 1 in x
Out[3]: True

In [4]: y = {1:2,3:4}

In [5]: 1 in y
Out[5]: True

(in in Hugo doesn’t work with maps as well at the moment).
Generally, I got the feeling that Hugo right now plays much better with arrays than maps. Maybe there’s a way to convert map into two different arrays? (first array is the keys, second is the values)

Thanks for your help.

p.s
I just realized that if where were implemented to look by key in maps that doesn’t really help my case. But maybe other ideas might follow.

For color for anyone following at home, here’s how this is currently worked around (@m1keil and I are working on the same project together) :

        {{ range $.Site.Data.events }}
          {{ if eq .status "past" }}
            <li><a href = "/events/{{ .friendly }}/welcome">{{ .city }}</a></li>
          {{ end }}
        {{ end }}