Calculating with Twig
Do you know this situation? A simple order form, without a large webshop implementation, but you would still like to
have the VAT and the total shown in the e-mail? No problem at all with the Notification Center Pro, we can create our own tokens for the VAT and the total and then use them. Let’s assume we have a form field called number_of_brochures where the customer can brochures. Each brochure costs 4 Euros. If someone now orders 5 brochures, we would like to send a mail with 20 Euro plus 3.80 Euro VAT (19% for Germany in this example) and a total amount of 23.80 Euro.
For example, we write the following in our mail:
So könnte unsere Twig-Logik könnte dann wie folgt aussehen:
We now copy this logic into 3 tokens and output the desired variable in each case:
- token
subtotaluses the above logic and{{ subtotal }} - token
taxuses the above logic and{{ tax }} - token
totaluses the above logic and{{ total }}
Tada! 🎉
Tip
Use the Twig number_format filter to format the numbers to your liking!