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.
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.
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.