CMS Development

rohansdeeson
Top Contributor

HubDB Groupby Year and Month

SOLVE

So I want to be able to group items in hubdb by year and month

I found that you can do the following in jinja, but date.year and date.month cannot be used in hubl? Can anyone think of how this can be replicated in hubl.

 

{% for year, year_group in EventsList|groupby('date.year') %}
    {% for month, list in year_group|groupby('date.month') %}
        <b>{{ month }} {{ year }}</b><br />
        {% for event in list %}
            <i>{{event.title}}</i>
        {% endfor %}
    {% endfor %}
{% endfor %}
0 Upvotes
2 Accepted solutions
Solution
Anonymous
Not applicable

HubDB Groupby Year and Month

SOLVE

If you are building it out in HubDB, you could setup a column for year and for month... then you can filter or pull specific groups from the HubDB based on year/month as needed on the front end.

View solution in original post

0 Upvotes
John
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

HubDB Groupby Year and Month

SOLVE

If anyone doesn't want to create extra columns for content creators to fill out, then check out my solution in this twitter thread.

Basically the idea is to modify an event dictionary (object) by updating it with month and year properties. You  set month and year properties by using the datetimeformat filter on the the datetime value.

 

Then you can utilize the groupby filter with the newly added month and year properties.



I like kudos almost as much as cake – a close second.

View solution in original post

0 Upvotes
2 Replies 2
John
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

HubDB Groupby Year and Month

SOLVE

If anyone doesn't want to create extra columns for content creators to fill out, then check out my solution in this twitter thread.

Basically the idea is to modify an event dictionary (object) by updating it with month and year properties. You  set month and year properties by using the datetimeformat filter on the the datetime value.

 

Then you can utilize the groupby filter with the newly added month and year properties.



I like kudos almost as much as cake – a close second.

0 Upvotes
Solution
Anonymous
Not applicable

HubDB Groupby Year and Month

SOLVE

If you are building it out in HubDB, you could setup a column for year and for month... then you can filter or pull specific groups from the HubDB based on year/month as needed on the front end.

0 Upvotes