CMS Development

tmcmillan99
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Assistance with correct Hubl syntax - HubDB rows

SOLVE

I know this is going to be a simple solution but have spent way too much time trying to figure out the correct syntax. So I am reaching out for assistance.

 

I have a for loop returning rows from a HubDB table. The goal is to only return one instance of each value listed.

An example of my current results-

cat1

cat1

cat1

cat2

cat2

cat3

cat3

 

Thanks,

Terry McMillan

0 Upvotes
1 Accepted solution
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Assistance with correct Hubl syntax - HubDB rows

SOLVE

Hi @tmcmillan99,

 

You could achieve this with a couple of for loops.

 

First, you would set a variable called "all_rows" which would be an array and then loop through your HubDB table to add items to that array from the table. In this case I am using the "name" of column of the row, you would need to adjust to your column name, if different:

 

{% set all_rows = [] %}

{% for row in hubdb_table_rows(xxxxxxxxx) %}
  {% do all_rows.append(row.name) %}
{% endfor %}

 

Then you can use that array to loop through the values and only show the item once, without repeating it, by using the "unique" filter:

 

{% for item in all_rows|unique %}
  {{ item }}<br>
{% endfor %}

 

Based on your example, the result you should get is:

 

cat1

cat2

cat3

 

 

Hope this helps!


✔️ Did this post help answer your query? Help the community by marking it as a solution.

View solution in original post

2 Replies 2
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Assistance with correct Hubl syntax - HubDB rows

SOLVE

Hi @tmcmillan99,

 

You could achieve this with a couple of for loops.

 

First, you would set a variable called "all_rows" which would be an array and then loop through your HubDB table to add items to that array from the table. In this case I am using the "name" of column of the row, you would need to adjust to your column name, if different:

 

{% set all_rows = [] %}

{% for row in hubdb_table_rows(xxxxxxxxx) %}
  {% do all_rows.append(row.name) %}
{% endfor %}

 

Then you can use that array to loop through the values and only show the item once, without repeating it, by using the "unique" filter:

 

{% for item in all_rows|unique %}
  {{ item }}<br>
{% endfor %}

 

Based on your example, the result you should get is:

 

cat1

cat2

cat3

 

 

Hope this helps!


✔️ Did this post help answer your query? Help the community by marking it as a solution.

tmcmillan99
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Assistance with correct Hubl syntax - HubDB rows

SOLVE

@evaldas Thanks for the reply and suggestions on the hubl code. That's waht I was the piece I was missing. Much appreciated.

 

Terry