Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Mustache issue with array of objects

So I searched for similar question and I applied their answers but it doesn't seem to work in my case. It's frustrating 'cause it should be something simple.

So, I use mustache template to render data that come from a node server with sockets.

It works fine with one object but when I try to iterate through an array of object it just render a blank page.

This is my socket, the push is just to simulate what I'm gonna do next (get a new object in the array)

let productsTab = [{
    prodName: prodName,
    prodPrice: prodPrice,
    quantity: quantity,
    quantityUnit: quantityUnit,
    isQuantityManual: isQuantityManual,
    hasQuantityUnit: hasQuantityUnit,
    totalPrice: totalPrice
}];

productsTab.push({
    prodName: prodName,
    prodPrice: prodPrice,
    quantity: quantity,
    quantityUnit: quantityUnit,
    isQuantityManual: isQuantityManual,
    hasQuantityUnit: hasQuantityUnit,
    totalPrice: totalPrice
});

res.render('displayProduct', productsTab);

this is the log of my array

[
  {
    prodName: 'name',
    prodPrice: 'price',
    quantity: '1',
    quantityUnit: '',
    isQuantityManual: false,
    hasQuantityUnit: false,
    totalPrice: 'price'
  },
  {
    prodName: 'name',
    prodPrice: 'price',
    quantity: '1',
    quantityUnit: '',
    isQuantityManual: false,
    hasQuantityUnit: false,
    totalPrice: 'price'
  }
]

And finally this is my mustache template

{{#productsTab}}
<div>
    <div>
        {{ prodName}}
    </div>
    <div>
        {{{ prodPrice }}}
        {{ #hasQuantityUnit }}
        text
        {{ /hasQuantityUnit }}
    </div>
</div>
<div>
    <div>
        x {{ quantity }} {{ quantityUnit }}
        {{ #isQuantityManual }}
            (MAN)
        {{ /isQuantityManual }}
    </div>
    <div>
        = {{{ totalPrice }}}
    </div>
</div>
{{/productsTab}}

It works fine with just an object (not an array) without the {{#}} loop feature so the issue must come from the array...

I need some help please

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ok, I got it. It is when I render my template

res.render('displayProduct', productsTab);

This works only when the props you pass is an object but I had to iterate through an array of object so I did this :

res.render('displayProduct', { productsTab });

Hope it will help someone that got a brain freeze like me.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!