Hi there - I'm using the below HUBL to group HUBDB rows by month, but is it possible to do this more efficiently please in a way that always creates the month groups automatically and always with the latest month at the top? Many thanks!
{% set table = hubdb_table_rows(2656152, queryparam) %} {% set current_dt = unixtimestamp( local_dt ) %} {% set query = "release_date__gte="~current_dt~"&orderBy=release_date" %}
<h2>July 2020</h2> {% for row in table %} {% if (row['release_date']|datetimeformat('%m/%Y')) == '07/2020' %} <h3>{{ row["name"] }}</h3> <p>RELEASED: {{ row.release_date|datetimeformat('%e %B %Y') }}</p> <h4>What's new?</h4> <p>{{ row["whats_new"] }}</p> <h4>How does this help you?</h4> <p>{{ row["how_does_this_help_you"] }}</p> {% endif %} {% endfor %}
<h2>June 2020</h2> {% for row in table %} {% if (row['release_date']|datetimeformat('%m/%Y')) == '06/2020' %} <h3>{{ row["name"] }}</h3> <p>RELEASED: {{ row.release_date|datetimeformat('%e %B %Y') }}</p> <h4>What's new?</h4> <p>{{ row["whats_new"] }}</p> <h4>How does this help you?</h4> <p>{{ row["how_does_this_help_you"] }}</p> {% endif %} {% endfor %}
<h2>May 2020</h2> {% for row in table %} {% if (row['release_date']|datetimeformat('%m/%Y')) == '05/2020' %} <h3>{{ row["name"] }}</h3> <p>RELEASED: {{ row.release_date|datetimeformat('%e %B %Y') }}</p> <h4>What's new?</h4> <p>{{ row["whats_new"] }}</p> <h4>How does this help you?</h4> <p>{{ row["how_does_this_help_you"] }}</p> {% endif %} {% endfor %}
Pardon my dely here, I found a little time this moning to hunt down a few old solution that I had mentioned before. Hopefully these examples can get you moving a little faster:
So i think we found a solution for this a year ago or so, but i can't seem to track it down.
But at a glance I would approach as so:
Retrieve the full list /collection of quiried results
Order the entire list/collection by date (if not done via your query "orderBy")
Loop through this list and push the separate month into their own lists/collections
Finally display the data with another loop or somehting similar
This way you'd be formatting and destructuring your data outside of your display logic.
One more thing:
When querying you could possibly filter the results, only returning the 2020 items. This would save you the trouble of matching the month and date. That separation if possible could make the solution substantially more ellegant and reusable.
Sorry I cant dig into the code right now or i'd provide a little more for you.
Hope this gets you going
EDIT:
Using a macro with a month param passed in would also reduce the code you need to write and make it as modular as is possible!
Thanks @Kevin-C and @sharonlicari - really appreciate this. If it's possible to locate or help with the code to achieve this I'd be massively grateful.
Pardon my dely here, I found a little time this moning to hunt down a few old solution that I had mentioned before. Hopefully these examples can get you moving a little faster: