Nutrient value table with NRV calculation

Topic summary

A user encountered a Liquid syntax error when building a nutrient value table with automatic NRV (Nutrient Reference Value) percentage calculations. The error message indicated: “Expected dotdot but found pipe in” when attempting to chain multiple operations.

Root Cause:
The issue stemmed from using parentheses to group Liquid filter operations, which is not valid Liquid syntax.

Solution Provided:

  • Remove parentheses from the filter chain
  • Liquid filters apply left-to-right automatically
  • Break complex calculations into capture blocks for better readability

Code Fix:
Instead of: {{ (product.metafields.custom.energie | divided_by: energie_ref | times: 100) | round: 2 }}

Use: {{ product.metafields.custom.energie | divided_by: energie_ref | times: 100 | round: 2 }}

Or use capture blocks to separate the calculation steps. The responder offered to follow up if further assistance was needed.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

Hi, I’m trying to create a nutrient value table that automatically calculates the nutrient reference values in %. When I add the code, it shows me the following liquid syntax error:

"Expected dotdot but found pipe in “{{ (product.metafields.custom.energie | divided_by: energie_ref | times: 100) | round: 2 }}”

Can anyone make sense of this? Thanks in advance for the help!!

Here’s a part of the full code I’m trying to add, just in case this might be useful for troubleshooting:

{% assign energie_ref = 2000 %}

{% if product.metafields.custom.energie %}
      {% assign has_nutrition_info = true %}
      
        Energie
        {{ product.metafields.custom.energie }} kcal
        {{ (product.metafields.custom.energie | divided_by: energie_ref | times: 100) | round: 2 }}%
      
    {% endif %}

Hi @fm_vlv

In Liquid, you don’t need to use parentheses to group operations - the filters are applied from left to right.

Please try the following code instead.

{{ product.metafields.custom.energie | divided_by: energie_ref | times: 100 | round: 2 }}

or you can even break it down as follows.

{% capture result %}
  {{ product.metafields.custom.energie | divided_by: energie_ref | times: 100 }}
{% endcapture %}
{{ result | round: 2 }}

Let me know if it helps.

Thank you.

1 Like