CMS Development

bradhardinge
Participant

HubDB filter using selectattr and foreign id for another table

Résolue

I have a page displaying data from a HubDB table. It needs to be grouped by category. The categories are stored in another HubDB table. I can get this working using multiple hubdb_table_rows functions and filtering like below:

 

 

 

hubdb_table_rows(table_id, '&category__contains=' ~ category)

 

 

 

Problem is as there are more than 10 categories  I hit the table scans limit. I'd prefer to do one hubdb_table_rows and use selectattr but I can't get this working with a foreign id column type. Any ideas?

 

 

 

rows|selectattr('category.name','contains','Category Name')

 

 

0 Votes
1 Solution acceptée
alyssamwilie
Solution
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

HubDB filter using selectattr and foreign id for another table

Résolue

@bradhardinge 

 

You could loop through the categories table,  within that loop through your main table, and then use an if statement to find rows containing the currently looped category.

 

{% set rows = hubdb_table_rows(tableid) %}
{% set categories = hubdb_table_rows(tableid) %}

{# Loop through categories table #}
{% for category in categories %}
  <h2>{{ category.name }}</h2>
  
  {# Loop through main table #}
  {% for row in rows %}
    {# Check if row contains category #}
    {% if category.name is within row.categories|map('name') %}
      <p>{{ row.title }}</p>
    {% endif %}
  {% endfor %}
{% endfor %}

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.

Voir la solution dans l'envoi d'origine

3 Réponses
bradhardinge
Participant

HubDB filter using selectattr and foreign id for another table

Résolue

Thanks @alyssamwilie 🙂

alyssamwilie
Solution
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

HubDB filter using selectattr and foreign id for another table

Résolue

@bradhardinge 

 

You could loop through the categories table,  within that loop through your main table, and then use an if statement to find rows containing the currently looped category.

 

{% set rows = hubdb_table_rows(tableid) %}
{% set categories = hubdb_table_rows(tableid) %}

{# Loop through categories table #}
{% for category in categories %}
  <h2>{{ category.name }}</h2>
  
  {# Loop through main table #}
  {% for row in rows %}
    {# Check if row contains category #}
    {% if category.name is within row.categories|map('name') %}
      <p>{{ row.title }}</p>
    {% endif %}
  {% endfor %}
{% endfor %}

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

HubDB filter using selectattr and foreign id for another table

Résolue

@bradhardinge ,

Let me introduce you to @alyssamwilie .  She is about as gifted as they come particularly around HubDB.

@alyssamwilie what say you?

0 Votes