最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does != do in jadepug? - Stack Overflow

programmeradmin5浏览0评论

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();
});

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();
});
Share Improve this question asked Jun 18, 2016 at 4:31 CodeCrackCodeCrack 5,37311 gold badges46 silver badges74 bronze badges 2
  • It appears to be a way to output content without needing a parent tag. – Bill Criswell Commented Jun 18, 2016 at 4:49
  • Somewhat documented here ("Unescaped Buffered Code"). – robertklep Commented Jun 18, 2016 at 8:28
Add a ment  | 

2 Answers 2

Reset to default 18

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/language/interpolation.html

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.

发布评论

评论列表(0)

  1. 暂无评论