Friday, 12 May 2017

Jade template in Node JS doesn't render

I have a problem with Jade. I have this route, I paste a part of it:

user.js (router.post('/new')

connection.query('SELECT Id FROM Clinica where Estado=0 AND Id=?', nuevo_usuario.Id_Clinica, function (err, rows) {

    if (err) throw err;
    if (!rows.length) {
        console.log('No existe esa clinica');
        res.render('../views/altaUsuario', { user_clinica: 'No'});

In Jade, I have this: altaUsuario.jade

if user_clinica == 'No'
        br
        p.container= clinica
        p.container Lo siento, pero no existe la clinica.

If I add a 'Id_Clinica' and it doesn't exist, in the template appears the message. If I add the next code in altaUsuario.jade:

   - prueba = listado
   - each val, key in prueba
    li #{val.Id}: #{val.Nombre}

Jade's template doesn't render. I don't know why. The variable 'listado' appears in: users.js('/altausuario').

router.get('/altausuario', function (req, res) {

connection.query('SELECT Id,Nombre FROM Clinica WHERE Estado=0', function (err, results) {

    if (err) throw err;
    listado_clinicas = results;

    console.log(listado_clinicas);
    res.render('../views/altaUsuario', { listado: listado_clinicas });
});

})

I need the 'listado' to do a combolist in the jade's template.

I hope I explain enough to you understand me. I'm sorry for my English.

Thank you very much.



via Sebas

No comments:

Post a Comment