Add 2 variables

Hello,

I need some help adding 2 variables. The variables have the correct value and printing them individually works just fine. But when I try to add them together, it doesn’t want to work anymore. totalcosts keeps giving the wrong value. I tried different things but I think the problem has something to do with the brackets!
Schermafbeelding 2020-02-23 om 14.25.16|644x76

Thank you in advance

Hi Lodillen

Without testing your code I could notice that you are using a print syntax (within {{ }}) within your logic syntax (within {% %}). This is not necessary when creating a different variable.

May I suggest you alter your code as followed:
{% assign totalcosts = extracosts + custom.amortisation.value %}

Best regards

Thank you for responding!
I changed my code to the following:
Schermafbeelding 2020-02-25 om 17.39.10

However, it doesn’t seem to work. The result doesn’t print.

Hi Lodillen

There should not be a space when calculating with variables or any value in liquid.
{% assign totalcosts = extracosts+custom.amortisation.value %}

But there is still a second issue in your code:
You custom field ‘custom.amortisation.value’ shows a default value of 15000, but does not actually store that amount. This can be resolved by assigning it to another variable.
{% input custom.amortisation.value as:currency default:15000 assign:amortisation %}

in the variable ‘totalcosts’ you can now call upon the new variable.

Code should look like this:
{% stripnewlines %} |--------- |---15%---:+ {% newline %} | Other costs | {% input custom.amortisation.value as:currency default:15000 assign:amortisation %} {% newline %} {% assign extracosts = $1 %} {% assign totalcosts = extracosts+amortisation %} | | {{ totalcosts | currency }} {% endstripnewlines %}

Best regards
Kevin