Expand my Community achievements bar.

Adobe Journey Optimizer Community Lens 7th edition is out.
SOLVED

How to use values from Handlebars helpers with math ?

Avatar

Level 1

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!

1 Accepted Solution

Avatar

Correct answer by
Level 1

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}}

 

View solution in original post

3 Replies

Avatar

Community Advisor

@Adrian771, Did you try these functions mentioned in the documentation?

Thanks, Sathees

Avatar

Level 1

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}}

 

 

 

Avatar

Correct answer by
Level 1

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}}