What does != do in jade/pug?

 ̄綄美尐妖づ 提交于 2019-12-07 06:47:35

问题


How does != work in jade code below.. != messages()

extends layout

block content
 .spacer
 .container
  .row
   .col-lg-8.col-lg-offset-2.col-md-10.col-md-offset-1
    a(class='btn btn-tiny btn-primary' href='/manage/categories/add') Create Category
    h1= title
     small
      a(href='/manage/articles')  Manage Articles
    != messages()
    table(class='table table-striped')
     tr
      th Category Title
      th
     each category, i in categories
      tr
       td #{category.title}
       td 
        a(class="btn btn-tiny btn-default" href="/manage/categories/edit/#{category._id}") Edit

app.js

app.use(require('connect-flash')());
app.use(function (req, res, next) {
  res.locals.messages = require('express-messages')(req, res);
  next();
});

回答1:


It is called "interpolation".

It means that "messages()" is escaped, e.g. if you have following code:

var randomText = '<p> this is a <strong>text</strong></p>'
p= randomText

which would normally, unescaped, produce just what it is:

'<p> this is a <strong>text</strong></p>'

but if I typed this:

p!= randomText

it would actually became a p tag, looking exactly like this:

this is a text

Hope it helps you :-)

You can read more about in the documentation, here: https://pugjs.org/language/interpolation.html




回答2:


you should try

if(!messages())
 table(class='table table-striped')

you have to assign some value into left hand side. otherwise just validate into if condition.



来源:https://stackoverflow.com/questions/37893264/what-does-do-in-jade-pug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!