CMS Development

tommitchell
Contributor

Looking to group HubDB rows by month

SOLVE

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 %}

 

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Looking to group HubDB rows by month

SOLVE

Hey @tommitchell 

 

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:

 

Converting datetimeformat for StringToTime

HUBL limiting dates 

Convert basic date string to dateobject (no time in string)

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

4 Replies 4
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Looking to group HubDB rows by month

SOLVE

Thanks for the tag @sharonlicari 

 

 

Hey @tommitchell 

 

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:

  1. Retrieve the full list /collection of quiried results
  2. Order the entire list/collection by date (if not done via your query "orderBy")
  3. Loop through this list and push the separate month into their own lists/collections
  4. 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!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
tommitchell
Contributor

Looking to group HubDB rows by month

SOLVE

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.

0 Upvotes
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Looking to group HubDB rows by month

SOLVE

Hey @tommitchell 

 

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:

 

Converting datetimeformat for StringToTime

HUBL limiting dates 

Convert basic date string to dateobject (no time in string)

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
sharonlicari
Community Manager
Community Manager

Looking to group HubDB rows by month

SOLVE

Hey @tommitchell        

 

Thank you for the information provided. I'll tag a few experts to see if they can share their knowledge.

 

Hey @Kevin-C @Chris-M @John  could you please share your thoughts with @tommitchell ?           

 

Thank you  & Happy Friday

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes