Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig math with variables

Tags:

math

twig

I want to do some math in twig. I've got 2 variables, price and quantity and i want to multiply them. But when I do it like this:

{{ {{ carts.price }} * {{ carts.quantity }} }}

It returns an error

A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".

How can i do this


1 Answers

It's because you duplicate {}, try something like this : {{ carts.price * carts.quantity }}

some docs https://twig.symfony.com/doc/2.x/templates.html#math

like image 111
Kr42 Avatar answered Jan 19 '26 09:01

Kr42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!