CMS Development

ben-duchy
Top Contributor

Show lowest value

I have a large database for a new housing estate that currently filters the info based on site location and house name;

 

{% set plot_info = table | selectattr ("site.name","equalto","London") | selectattr ("house_type","equalto","Sandringham") %}

 

Using {% for row in plot_info %} correctly shows me the list that meets the above crieria.

 

On a new line on the webpage I then want to display which of the 'Sandringham' plots is the cheapest. Is there a way to pull in the lowest value (price) row?

0 Upvotes
2 Replies 2
piersg
Key Advisor

Show lowest value

Hi @ben-duchy, you could sort by price, lowest first, and return only the first item in the loop.

{% for row in plot_info|sort(False, False, 'price') %}
  {% if loop.first %}
    {{row}}
  {% endif %}
{% endfor %}

 

ben-duchy
Top Contributor

Show lowest value

Hi @piersg 

 

I couldn't get your first line to work, but simply changing it to the below did the trick

{% set table = hubdb_table_rows(3409955, "&site=London&house_type=Sandringham&orderBy=amount") %}

 

Adding the above to your 'loop.first' worked a treat though, thanks 🙂