
Liquid sum filter
Hi,
I was told Betty Blocks has its own Liquid sum filter, to sum values of a particular property in a collection. I just can't really figure out the right way to use it.
I've grouped timesheet items like this:
{% assign timesheet_items_by_category = record.timesheet_items | group: "remuneration_rate" %}
Now I would like to sum, per category, the quantity properties. I was given this as example, but it creates an error:
{{ timesheet_item in timesheet_items_by_category.array | sum: ‘quantity’ }}
Error: Liquid error: undefined method `collect' for nil:NilClass
What is the correct way to use the sum filter?
After grouping, you can use {{ timesheet_item_by_category.key.name }} to get the name of the category. What is the complete structure the group filter creates / what attributes become available?
Hi,
I was told Betty Blocks has its own Liquid sum filter, to sum values of a particular property in a collection. I just can't really figure out the right way to use it.
I've grouped timesheet items like this:
{% assign timesheet_items_by_category = record.timesheet_items | group: "remuneration_rate" %}
Now I would like to sum, per category, the quantity properties. I was given this as example, but it creates an error:
{{ timesheet_item in timesheet_items_by_category.array | sum: ‘quantity’ }}
Error: Liquid error: undefined method `collect' for nil:NilClass
What is the correct way to use the sum filter?
After grouping, you can use {{ timesheet_item_by_category.key.name }} to get the name of the category. What is the complete structure the group filter creates / what attributes become available?
Login to reply