Nutrient value table with NRV calculation

Solved

Nutrient value table with NRV calculation

fm_vlv
Shopify Partner
11 1 3

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 %}
      <tr>
        <td>Energie</td>
        <td>{{ product.metafields.custom.energie }} kcal</td>
        <td>{{ (product.metafields.custom.energie | divided_by: energie_ref | times: 100) | round: 2 }}%</td>
      </tr>
    {% endif %}

 

Accepted Solution (1)

Entesta
Shopify Partner
80 8 20

This is an accepted solution.

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.

We value your feedback! Let us know if this helped by giving it a thumbs up or marking it as a solution or buy us a coffee.
Looking for Shopify experts to help you with your website? We are just one click away. Drop an email or say hi on WhatsApp to initiate a request support@entesta.com | +91 79083 21294
Entesta - Powering Your E-Commerce Journey with Shopify Expertise

View solution in original post

Reply 1 (1)

Entesta
Shopify Partner
80 8 20

This is an accepted solution.

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.

We value your feedback! Let us know if this helped by giving it a thumbs up or marking it as a solution or buy us a coffee.
Looking for Shopify experts to help you with your website? We are just one click away. Drop an email or say hi on WhatsApp to initiate a request support@entesta.com | +91 79083 21294
Entesta - Powering Your E-Commerce Journey with Shopify Expertise