We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Aug 30, 2018 5:42 AM
We use a blog to present and list our company events. I would like the listing to be sorted according to the date of the event. The date is saved in a custom module text field.
Is it possible to access the text field from the sort function in the foor loop?
Like this: {% for content in contents|sort(False, False, widgets.event_date.body.value) %}
Solved! Go to Solution.
Aug 31, 2018 8:40 AM
Hi there!
I am not sure if others on the community might have other thoughts but I don't believe you can sort blog listings by a custom module text field. The markup loops through "contents" which are the posts:
{% for content in contents %} <div class="post-item"> Post item markup that renders with each iteration. </div> {% endfor %}
And there are set blog variables.
Perhaps you could do something such as set topics with the date ('Event Date 2018-09-21', 'Event Date 2018-10-22') and then filter by topics with "Event Date" and sort alphabetically?
{% for content in contents %} {% for topic in content.topic_list %} {% if "Event Date" in topic.name %} {% topic.name|sort(False, False, 'name') %} {# Add your post markup here #} {% endif %} {% endfor %} {% endfor %}
(I haven't tested this code, I'm just combining looping through a topic and sort).
I've noticed @Jsum is great at this type of blog HubL wizardry so he might have a better idea 🙂
Another more common way of listing events in HubSpot would be to use HubDB. Here is a tutorial on how to do so.
I hope that helps!
HubSpot Design / Development / Automation
If this helped, please mark it as the solution to your question, thanks!
Aug 31, 2018 8:40 AM
Hi there!
I am not sure if others on the community might have other thoughts but I don't believe you can sort blog listings by a custom module text field. The markup loops through "contents" which are the posts:
{% for content in contents %} <div class="post-item"> Post item markup that renders with each iteration. </div> {% endfor %}
And there are set blog variables.
Perhaps you could do something such as set topics with the date ('Event Date 2018-09-21', 'Event Date 2018-10-22') and then filter by topics with "Event Date" and sort alphabetically?
{% for content in contents %} {% for topic in content.topic_list %} {% if "Event Date" in topic.name %} {% topic.name|sort(False, False, 'name') %} {# Add your post markup here #} {% endif %} {% endfor %} {% endfor %}
(I haven't tested this code, I'm just combining looping through a topic and sort).
I've noticed @Jsum is great at this type of blog HubL wizardry so he might have a better idea 🙂
Another more common way of listing events in HubSpot would be to use HubDB. Here is a tutorial on how to do so.
I hope that helps!
HubSpot Design / Development / Automation
If this helped, please mark it as the solution to your question, thanks!
Aug 31, 2018 9:38 AM
This HubDB solution is very helpful. It feels a bit unnecessary to have to add the events in more than one place, but seems like a pretty quick and straight forward solution.
Thank you!