How to define inline variable in Pug
In front of var you should write "-"
div
each discount in el.Discounts
if trxn.category != category
- var discountAmount = discount.amount * -1
- var distTotal = distTotal + discount.amount
p= distTotal
Arpit Kumar
let me = { _id 😍: 'apmeena' name 📛: 'Arpit Kumar', gender 💪: 'M', email 📧: 'arp*********@gmail.com', mobile 📱: '74******12', isSingle 👦: false, inLove 💑: true, isMorningBird 🐦: true, isNightOwl 🐥: false, favouriteProgrammingLanguage 💻: 'JavaScript', isHappy 🙋: true, inspiredBy 🔋: ['grandfather', 'father'], isCreative 🎨: true, hardWorker 🔨: true, loveCleanCode 🌴: true, believeInShowOff 📷: false, emotional 😟: true, hungryForProgrammingChallenge 🐈: true, loveSleep 😴: true, loveNation 🚩: true, believeInGod ✴: true, believeInAlien 👿: true, isGoodLooking 🌹: undefined, loveAnimation 🎠: true } 😍 😗 😀
Updated on June 29, 2022Comments
-
Arpit Kumar almost 2 years
I am using Pug template engine with Node + Express app.
I need some calculation in the Pug file. For example, I have an array of object and I have to print the sum of all object's amount field and need to show all amount in
table
.for that, I am using
each
loop available in Pug.I am trying like this :
div each discount in el.Discounts if trxn.category != category var discountAmount = discount.amount * -1 var distTotal = distTotal + discount.amount p= distTotal
But it is not working, I want to declare and update the inline variable.
How can I achieve this?
Thanks.