Reputation: 113
I wrote this code and I get the error jade iteration: cannot read property 'length' of undefined trying to send data to pug view and i cannot read it because it's wrong
app.get('/about', (req, res)=>{
var partners =[
{ "name":"Name1", "image": "img1.jpg" },
{ "name": "Name2", "image": "img2.jpg" },
{"name":"Name3", "image": "img3.jpg" }
];
let lang = getLang(req, res, ['about']);
res.render('about', {partners , ...lang});
});
extends layout
block content
.subhead
h2= about.title
.content.about
for item in about.team
div.team
h3
span= item[0]
small= item[1]
p= item[2]
each partner in partners
li.swiper-slide
img(src=partner.image, alt=partner.name)
Upvotes: 0
Views: 720
Reputation: 7802
That's the error that comes up when the pug template isn't being passed the variable properly. I'd bet that your node server isn't properly interpreting your "new" JSON syntax.
Use this more basic JSON instead and it will work:
res.render('about', {
"partners": partners,
"lang": lang
});
Upvotes: 1