将节点JS的值传递给Jade
我正在尝试从节点js的参数转移到我的Jade页面中的input标记,这里是我的代码:
节点js:
res.render("index" ,{title: userName});
翡翠页(叫'索引'):
.input input(type='text', value= #{title} , maxlength='15')
我在这里做错了什么?
这是我的错误信息:
48 | input(type ='text',value =#{title},maxlength = '15')
Function(native)意外的标记ILLEGAL
`
你正在使用像这里描述的转义string插值: http : //jade-lang.com/reference/interpolation/这不作为属性,你必须使用缓冲的代码,如下所述: http:// jade- lang.com/reference/code/
它看起来像这样:
// escaped code .input input(type='text', value= title , maxlength='15') // unescaped code .input input(type='text', value!= title , maxlength='15')
如果你想为你的属性使用一个对象,你可以用input&attributes(object)
来处理它,就像这里所描述的那样: http : //jade-lang.com/reference/attributes/#and-attributes
Node.js的
res.render("index" ,{ input: { type: 'text', title: userName, maxlength: '15', name: 'myInputName' } });
玉:
.input input&attributes(input)
两者的结果:
<div class="input"> <input type="text" value="username" maxlength="15" name="myInputName" /> </div>
这里是一个工作笔无节点的例子在翡翠: http ://codepen.io/pure180/pen/oLPGJy
它会按原样工作: value=title
?
.input input(type='text', value=title , maxlength='15')