【问题标题】:jade html escaped string玉 html 转义字符串
【发布时间】:2015-01-11 15:31:44
【问题描述】:

我对 Jade 有疑问,我从 db 中获取了一个未转义的字符串(如下所示:

"<mo>&amp"

这个字符串可以包含一些html代码,我将字符串传递给页面

res.render('page',f(){})

从布局中,我用 !{t.text} 标记字符串,但未呈现 html 代码,似乎打印的是纯文本。错误在哪里?

【问题讨论】:

  • f() 返回什么?在你的玉中,你指的是“t.text”,我假设 f() 返回一个看起来像这样的对象: {t: {text: "<mo>&amp"}} 根据结果,我打赌已定义但 t.text 未定义

标签: html node.js escaping pug


【解决方案1】:
  1. 我设置了默认的express 应用程序,它使用jade 作为其模板引擎。

  2. 修改routes -&gt; index.js以传递一些编码文本

router.get('/', function(req, res) {
  res.render('index', { title: 'Express', encodedText: '&lt;mo&gt;&amp' });
});
  1. 修改 views -&gt; index.jade 以显示此文本
block content
  h1= title
  p Welcome to #{title}
  p Encoded text !{encodedText}
  1. 结果似乎还可以

【讨论】:

    猜你喜欢
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 2015-09-27
    • 2012-04-11
    • 2020-03-14
    相关资源
    最近更新 更多