How to send an object / array from node to pug (jade) and render it?

2

Since node, I have something like this:

var nombres = ['Saab','Volvo','BMW'];

app.get('/', function(req, res){
  res.render('index', {nombres: nombres});
});

then in pug:

- var nombres1 = {nombres};
html(lang="es")
head
title= "Itris INFO"
body
script.
  console.log(!{JSON.stringify(nombres1)});
ul
  each nombre in nombres1
    li= nombre

But when you render, in the html it shows me:

  • Saab, Volvo, BMW

And the idea is to show something like this:

  • Saab

  • Volvo

  • BMW

I tried all the options they say in other posts about this and nothing works. I added the script tag in order to see the object in the console, and there it shows me an array of 3 elements. However, when I use it in pug it does not work ... I do not know if it takes as a string or that ...

    
asked by Damián Maenza 26.07.2017 в 02:31
source

2 answers

0

Try this

// Routes

 app.get('/',(req,res)=>{
   let nombres = ['Saab','Volvo','BMW'];
   res.render('index',{nombres}); // o {'nombres':nombres}
 });

// views / index.pug

ul
  each nombre in nombres
       li= nombre

Source: link

    
answered by 26.07.2017 / 03:39
source
0

Try this:

each nombre, i in nombres
  li #{nombre}

I've attached a link about Jade's syntax

    
answered by 26.07.2017 в 02:55