APIs & Integrations

Not applicable

Sorting HubDB based on page URL

I am trying to display content from a HubDB based on the URL of the page the user lands on. My goal is to use one HubDB and one custom module that sorts and displays the correlating content. In my project I have 52 separate pages (for each state, DC, PR). Using the URL to determine the correct content to list. So the user lands on the California page, and the custom module lists all of the content from the HubDB with the specified properties in the queryparam such as quarter, year, stated. Currently, my code lists all of the content and does not take into account the URL. Do I need to include the HubDB in the Website Page? Or will it work the way I call the HubDB by ID in the custom module?

 {% set table = hubdb_table_rows(700276, '&quarter__eq=Q3&year__eq=2018') %}
 {# sets the different query parameters using request path for hubdb query #}


 <section class="container-fluid">
  {% for row in table %}

   {% if request.path == "/press/category/archives/california/" %}
    {% set queryparam = queryparam ~ "&state=CA" %}

   <h2 class="listing-headline">{{ row['quarter'] }}&nbsp;{{ row['year'] }}&nbsp;|&nbsp;Embargoed Until {{ row['date'] }} at 12:01 a.m. ET</h2>
  <div class="row-fluid">
    <div class="listing-content">
      <ul>	
        <li><a target="_blank" href="{{ row['embed'] }}">{{ row['name'] }}</a></li>
     </ul>
   </div>
  </div>
  {% endif %}
  </section>

 {% else if request.path == "/press/category/archives/ohio/" %}
 {% set queryparam = queryparam ~ "&state=OH" %}
 <section class="container-fluid">
   <h2 class="listing-headline">{{ row['quarter'] }}&nbsp;{{ row['year'] }}&nbsp;|&nbsp;Embargoed Until {{ row['date'] }} at 12:01 a.m. ET</h2>
   <div class="row-fluid">
     <div class="listing-content">
       <ul>  
        <li><a target="_blank" href="{{ row['embed'] }}">{{ row['name'] }}</a></li>
      </ul>
    </div>
  </div>
 </section>

 {% else if request.path == "/press/category/archives/new-york/" %}
 {% set queryparam = queryparam ~ "&state=NY" %}
 <section class="container-fluid">
   <h2 class="listing-headline">{{ row['quarter'] }}&nbsp;{{ row['year'] }}&nbsp;|&nbsp;Embargoed Until {{ row['date'] }} at 12:01 a.m. ET</h2>
   <div class="row-fluid">
    <div class="listing-content">
       <ul>  
         <li><a target="_blank" href="{{ row['embed'] }}">{{ row['name'] }}</a></li>
      </ul>
    </div>
  </div>
</section>
 {% endfor %}
0 Upvotes
1 Reply 1
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Sorting HubDB based on page URL

Hi @fly.space.age,

I'm not entirely sure I understand your question. You should be able to include query parameters in your HubDB filters, so based on my understanding of your goal this should work by calling the HubDB functions in your custom modules. Are you running into issues doing this?

0 Upvotes