CMS Development

SBurnett28
Member

HubDB Queryparam filter based on page path/URL

Hi there, 

 

I'm currently trying to make a product/service listing page with the HubDB and so far everything is great, but I'm struggling with trying to get the queryparam to work based on  page path. 

 

A section of the code is here: 

 

 

{% elif dynamic_page_route_level == 1 %}

    {% set queryparam = "" %}

    {% if request.path == "/sales/ipek" or "/sales/flir" or "/sales/ionix" or "/sales/agilent" or "/sales/manup-key" or "/sales/pearpoint" or "/sales/sky-eye" or "/sales/cordex" or "/sales/senceive" or "/sales/cygnus" %}
      {% set queryparam = queryparam ~ "&available_to__contains=Buy"~"&brand="~dynamic_page_hubdb_row.name %}

    {% elif request.path == "/rentals/video-probes" %}
      {% set queryparam = queryparam ~ "&category__contains=Video Probes"~dynamic_page_hubdb_row.name %}
    {% endif %} 
    
    {% set childTable = hubdb_table_rows(dynamic_page_hubdb_row.hs_child_table_id, queryparam) %}
       
    {% if childTable == [] %}
    <p style="color: black;">Sorry, there were no items matching that description. If you are looking for something specific, feel free to contact us.</p>
    <p>request.path: {{ request.path }}</p>
    <p>dynamic_page_hubdb_row.name: {{ dynamic_page_hubdb_row.name }}</p>
    <p>queryparam: {{ queryparam }}</p>
    {% else %}
    <p>request.path: {{ request.path }}</p>
    <p>dynamic_page_hubdb_row.name: {{ dynamic_page_hubdb_row.name }}</p>
    <p>queryparam: {{ queryparam }}</p>
    <ul class="no-list l-cards l-gap--normal">
    {% for childRow in childTable %}
      <li class="c-card c-card--product l-gap--normal" style="background: linear-gradient(rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0.65)), url({{ childRow.image.url }}) center/cover;"><p class="h3">{{ childRow.product_name }}</p><a href="{{ request.path }}/{{childRow.hs_path}}" class="button">Find out more</a></li>
    {% endfor %}  
    </ul>
    
    {% endif %}

 

 

Which works on the Sales page as seen here:

filter working.JPG

However, it seems to be picking up the previous queryparam somehow on the Rentals page as seen here:

filter not working.JPG

The request.path and dynamic_page_hubdb_row.name is pulling through correctly, so I'm confused as to why the if statement on the page path isn't working. When I change the order of the code around so the "if page.path == /rentals" is before the "== /sales" then the queryparam changes to that one, so it's keeping whatever the first queryparam is for some reason and not working with the if statement and I can't figure out why. I also tried using blocks of if statements rather than if/elif but that didn't help either. I also tried adding a "set queryparam = """ in between in if statement block to try and "reset" the filter but that didn't work either.

 

The way I have it set up is a database of the products/items, and a database of categories/page types, as I needed the multi-level feature which doesn't work with only one database. I managed to get it working last night with a different method but it was incredibly verbose so I wanted to pare it down a bit this way, but it's not cooperating.

0 Upvotes
1 Reply 1
dennisedson
HubSpot Product Team
HubSpot Product Team

HubDB Queryparam filter based on page path/URL

@Anton , @Oezcan 

Who will be faster at helping here 😜