Trying to use HubDB to create an attendee list as such:
Company Name 1
Employee 1
Employee 2
Company Name 2
Employee 1
Employee 2
Is there an example/use case that goes over this sort of filtering? Right now I have a simple table that includes every attendee and their company, but I think the above is cleaner. My table has two columns, name, and company.
Hello @cives !
This possible with the following code, I have included further instructions and descriptions inside the comments of the snippet:
<!-- 1. helper variable to store the company to compare with the next one -->
{% set companyName = '' %}
<!-- 2. using the definition list html element as it is more appropriate with the company in the title -->
<dl>
<!-- 3. loop through the rows and order by company [REPLACE <HUBDB TABLE ID> AND <COMPANY ROW NAME> WITH YOUR ACTUAL HUBDB TABLE ID AND COMPANY ROW NAME FROM YOUR TABLE] -->
{% for row in hubdb_table_rows(<HUBDB TABLE ID>, "orderBy=<COMPANY ROW NAME>") %}
<!-- 4. check if the helper variable is empty (first item) or differrent from the previous one (we are in the next company in order) -->
{% if companyName eq '' or companyName ne row.company %}
<!-- 5. output the company name only if the above is true, means that while it is the same company it is not output -->
<dt>{{ row.company }}</dt>
{% endif %}
<!-- 6. after we output company name we output every employee from that company -->
<dd>{{ row.name }}</dd>
<!-- 7. now we store the company name so that we can compare it with the next one -->
{% set companyName = row.company %}
{% endfor %}
</dl>
See more info about the hubdb_table_rows function in this link.
If my answer was helpful please mark it as a solution.