Tal Tal - 1 year ago 85
Jade Question

Transfer value from Node JS to Jade

i am trying to transfer an argument from node js to Input Tag in my Jade page,
here is my code:

Node js :

res.render("index" ,{title: userName});

Jade Page (which called 'index') :

input(type='text', value= #{title} , maxlength='15')

What i am doing wrong here ?

Here is my error message :

48| input(type='text', value= #{title} , maxlength='15')

Unexpected token ILLEGAL
at Function (native)


Answer Source

You are using an escaped string interpolation like described here: http://jade-lang.com/reference/interpolation/ This doesn't work as attribute, you have to use buffered code, like described here: http://jade-lang.com/reference/code/

It would look like this:

// escaped code
    input(type='text', value= title ,  maxlength='15')
// unescaped code
    input(type='text', value!= title ,  maxlength='15')

If you want to use an object for your attributes, you can handle it with input&attributes(object), like descibed here: http://jade-lang.com/reference/attributes/#and-attributes


res.render("index" ,{
   input: {
      type: 'text',
      title: userName, 
      maxlength: '15',
      name: 'myInputName'



Result of both:

<div class="input">
   <input type="text" value="username" maxlength="15" name="myInputName" />

Here is a workinh Pen without Node as example in Jade: http://codepen.io/pure180/pen/oLPGJy

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download