Pagination for HubDB table in template has ceased working

I currently have a template set up to pull in data from HubDB dynamically. This template also includes pagination for the table which I pulled from this community post.

This was working as of two weeks ago and code hasn’t been changed since then, however the pagination has stopped working on the site.

Below is what I’m using in the template, much hasn’t changed from the original.

{% set table = hubdb_table_rows(dynamic_page_hubdb_table_id, "orderBy=-date&date__lt=" + local_dt|unixtimestamp) %}

{# set the number of items per batch #}
{% set batch_num = 4 %}

{% if table|length % batch_num == 0 %}
 {% set number_of_pages = (table|length / batch_num) %}
{% else %}
 {% set number_of_pages = (table|length / batch_num)|round(0, 'floor') + 1 %}
{% endif %}

{% if Query.page_num %}
 {% set page_num = Query.page_num %}
{% else %}
 {% set page_num = 1 %}
{% endif %}

{% for row in table|batch(batch_num) %}
 {% if loop.index == page_num %}
 {% for innerRow in row %}
 {% if innerRow %}
 <li>
 <h3><a href="{{ request.path }}/{{ innerRow.hs_path }}">{{ innerRow.hs_name }}</a></h3>
 </li> 
 {% endif %}
 {% endfor %}
 {% endif %}

 {% if loop.last %}
 {% if page_num > 1 %}
 <a href="{{ content.absolute_url }}?page_num={{ page_num|add(-1) }}#prev-events">Previous</a>
 {% endif %}

 {% if page_num < number_of_pages %}
 <a href="{{ content.absolute_url }}?page_num={{ page_num|add(1) }}#prev-events">Next</a>
 {% endif %}
 {% endif %}
{% endfor %} 

Is anyone using something similar and experiencing issues? If no, is there something outside of the code that would cause this to break? I’m not seeing any errors in the HubSpot dashboard.

Thank you!

Hi @SFurlong ,

As you’re filtering the data from the HubDB directly in the query I’ll start by debugging the table variable. Can you add the following below the table declaration and tell me what it’s containing:

<code>{{ table|pprint }}</code>

Bests,

Matthieu

matthieu.berard@markentive.com

Hey Matthieu!

My result is an array of the hubdb table rows. It appears to be listing all of the items that have been entered.

Thanks!

Great!

At first I was thinking that the pagination wasn’t displaying… My bad!
What’s exatcly not working with your pagination?

Bests,

Matthieu

matthieu.berard@markentive.com

Thanks for working through this with me Matthieu!

Currently the pagination “next” does display and clicking it will take you to the correct URL. However the results remain on the first page of items.

After clicking on the next link, what is the value of page_num in the URL?

I can’t really determine what’s wrong with your pagination. I mean your code is working fine on my end, the last thing I could think of that cause the problem is the value of the page_num in the URL…

Best,

Matthieu

matthieu.berard@markentive.com

Matthieu, thanks for suggesting to look at the query string. That really helped send me down the path to fixing this.

My page_num parameter was correctly coming up but getting stuck at 2. From what I can tell this line is no longer working and is just returning empty:

{% if Query.page_num %}

I replaced that with a request query and grab the number that way instead:

{% set query = request.query %}
{% set queryPage = query|replace("page_num=", "") %}
{% if queryPage %}

With this everything appears to be working as intended. Again, thank you!

Happy to read that you managed to solve the problem!

Have a nice day!

Best,

Matthieu

matthieu.berard@markentive.com