I have created a metaobject with a "rating" field. When I iterate over the metaobject_list in my section I see the expected data. However when I try calling a math filter on rating.value, it will return 0. Calling the same math filter on scale_min/scale_max values inside the same metaobject will yield the correct values.
Here is an example of calling a round filter on rating.value in a metaobject_list for loop:
{% assign rating = item.rating %}
Rating metafield: {{ rating }}<br>
Rating value: {{ rating.value}}<br>
Rating scale min: {{ rating.value.scale_min }}<br>
Rating scale max: {{ rating.value.scale_max }}<br>
Rating round: {{ rating.value | round }}<br>
Rating scale min round: {{ rating.value.scale_min | round }}<br>
Rating scale max round: {{ rating.value.scale_max | round }}<br>
Output:
Rating metafield: {"scale_min":"1.0","scale_max":"5.0","value":"4.5"} // As expected
Rating value: 4.5 // As expected
Rating scale min: 1.0 // As expected
Rating scale max: 5.0 // As expected
Rating round: 0 **Wrong! Should be 5**
Rating scale min round: 1 // As expected
Rating scale max round: 5 // As expected
Steps to recreate:
- Create a metaobject with a rating field
- Create entry for said object
- Read object in liquid and try using math filter on rating.value
Using {{ rating.value | plus: 0 | round }} to force a conversion to interger results in the same incorrect output.
It is strange that scale_min/max results in the correct value but value does not, give the all have the same type in the metafield.
I have created a metaobject with a "rating" field. When I iterate over the metaobject_list in my section I see the expected data. However when I try calling a math filter on rating.value, it will return 0. Calling the same math filter on scale_min/scale_max values inside the same metaobject will yield the correct values.
Here is an example of calling a round filter on rating.value in a metaobject_list for loop:
Steps to recreate:
Using
{{ rating.value | plus: 0 | round }}to force a conversion to interger results in the same incorrect output.It is strange that scale_min/max results in the correct value but value does not, give the all have the same type in the metafield.