Find highest number in loop

Hi @ben-duchy,
I used my doggie HubDB demo from before for this

{% set table = hubdb_table_rows(module.hubdbtable_field) %}

{% set weight_array = [] %}
{% for row in table %}
{% do weight_array.append( row.weight) %}
{% endfor %}
{% set sorted_array = weight_array|sort %}

{% for row in table %}
{{ row.name }}<br>
{{ row.weight }} {% if row.weight == sorted_array[0] %}is lowest{% elif row.weight == sorted_array[-1] %}is highest{% endif %}

<hr>
{% endfor %}

The sorted_array sorts the numbers lowest to highest, then you test your displayed values against sorted_array[0] (lowest) and sorted_array[-1] (highest)

I’m sure there’s other ways of doing it.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn