# Sort blog listing based on custom module field

**URL:** <https://community.hubspot.com/t/sort-blog-listing-based-on-custom-module-field/10024>\
**Category:** CMS Development\
**Created:** [August 30, 2018, 9:42am UTC](https://community.hubspot.com/t/sort-blog-listing-based-on-custom-module-field/10024 "2018-08-30T09:42:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannalofving](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hannalofving/32/104050_2.png) [@hannalofving](https://community.hubspot.com/u/hannalofving)\
**Post date:** [August 30, 2018, 9:42am UTC](https://community.hubspot.com/t/sort-blog-listing-based-on-custom-module-field/10024/1 "2018-08-30T09:42:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stephanie-OG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stephanie-og/32/73267_2.png) [@Stephanie-OG](https://community.hubspot.com/u/Stephanie-OG)\
**Post date:** [August 31, 2018, 12:40pm UTC](https://community.hubspot.com/t/sort-blog-listing-based-on-custom-module-field/10024/2 "2018-08-31T12:40:34Z")

</div>

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](https://designers.hubspot.com/docs/hubl/blog-content-markup)loops through “contents” which are the posts:

```auto
{% for content in contents %}
 <div class="post-item">
 Post item markup that renders with each iteration. 
 </div>
{% endfor %} 

```

And there are [set blog variables](https://designers.hubspot.com/docs/hubl/hubl-supported-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?

```auto
{% 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](http://www.stephanieogaygarcia.com/blog/set-featured-blog-posts-on-the-hubspot-blog-listings-page?utm_source=HubSpotCommunity) and [sort](https://designers.hubspot.com/docs/hubl/hubl-supported-filters)).

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](https://www.smartbugmedia.com/blog/creating-event-listing-using-hubdb) is a tutorial on how to do so.

I hope that helps!

* * *

[![|300](https://d2qpr2jzcazej7.cloudfront.net/original/2X/e/e6ddb445b684524bbcbd802044a9ca3919d1fbc7.png)](http://www.stephanieogaygarcia.com?utm_source=HubSpotCommunity)HubSpot Design / Development / Automation

[Website](http://www.stephanieogaygarcia.com?utm_source=HubSpotCommunity) | [Contact](http://www.stephanieogaygarcia.com/contact?utm_source=HubSpotCommunity)

_If this helped, please mark it as the solution to your question, thanks!_

---

<div class="post-metadata">

**Author:** ![hannalofving](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hannalofving/32/104050_2.png) [@hannalofving](https://community.hubspot.com/u/hannalofving)\
**Post date:** [August 31, 2018, 1:38pm UTC](https://community.hubspot.com/t/sort-blog-listing-based-on-custom-module-field/10024/3 "2018-08-31T13:38:35Z")

</div>

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!
