Hi !
I created a loop to extract all the product prices.
I need to use those values in math calculations.
What is the right syntax to achieve that ?
{{#each profile.productsInCart}}
This price = {{this.price}} <!-- This price = 22.88 (Working) -->
This Price + TVA = {{ 1.7*this.price }} <!-- Not working -->
This Price + TVA = {%= 1.7*this.price %} <!-- Not working -->
This Price + TVA = {%= 1.7*{{this.price}} %} <!-- Not working -->
{{/each}}
I can see the value for {{this.price}} , but I cannot use in other context (eg helper functions).
Thank you!
Solved! Go to Solution.
Views
Replies
Total Likes
I have found the issue, posting it here for others.
the query result It needs to be assigned to a variable (don't relay on default "this"), only then it can be referenced on functions:
{{#each profile.productsInCart as |product|}}
This price = {{product.price}} <!-- This price = 100 (Working) -->
Sum = {%= 100 + 100 %} <!-- Sum = 200 (Working) -->
Sum = {%= product.price + product.price %} <!-- Sum = 200 (Working) -->
{{/each}}
Views
Replies
Total Likes
@Adrian771, Did you try these functions mentioned in the documentation?
Views
Replies
Total Likes
Hi SatheeskannaK
yes I have used those functions, they work with static values but not with dynamic values, coming from the Handlebars loop:
{{#each profile.productsInCart}}
This price = {{this.price}} <!-- This price = 100 (Working) -->
Sum = {%= 100 + 100 %} <!-- Sum = 200 (Working) -->
Sum = {%= {{this.price}} + {{this.price}} %} <!-- Not Working -->
{{/each}}
Views
Replies
Total Likes
I have found the issue, posting it here for others.
the query result It needs to be assigned to a variable (don't relay on default "this"), only then it can be referenced on functions:
{{#each profile.productsInCart as |product|}}
This price = {{product.price}} <!-- This price = 100 (Working) -->
Sum = {%= 100 + 100 %} <!-- Sum = 200 (Working) -->
Sum = {%= product.price + product.price %} <!-- Sum = 200 (Working) -->
{{/each}}
Views
Replies
Total Likes
Views
Likes
Replies