jade html转义字符串 [英] jade html escaped string
本文介绍了jade html转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
& lt; mo&
此字符串可以包含一些html代码,我将该字符串传递到页面
res.render('page',f(){})
从布局我用!{t.text}标记字符串,但html代码没有渲染,似乎打印纯文本错误在哪里?
解决方案
-
我已经设置了默认的
express
应用程序,它使用/ code>作为其模板引擎。
-
修改
routes - > index.js
传递一些编码文本
路由器。 get('/',function(req,res){
res.render('index',{title:'Express',encodedText:'& lt; mo& gt& amp; amp}
});
视图 - > index.jade
显示此文本
块内容
h1 = title
p欢迎来到#{title}
p编码文本!{encodedText}
- 结果似乎OK
I have a problema with Jade, I take an unescaped string from db (something like this:
"<mo>&"
this string can contain some html code, I pass the string to the page with
res.render('page',f(){})
from the layout I stamp the string with !{t.text} but the html code is not rendered, seems that prints plain text. where is the error?
解决方案
I've set up default
express
app which usesjade
as its template engine.Modified
routes -> index.js
to pass some encoded text
router.get('/', function(req, res) {
res.render('index', { title: 'Express', encodedText: '<mo>&' });
});
- Modified
views -> index.jade
to display this text
block content
h1= title
p Welcome to #{title}
p Encoded text !{encodedText}
- Result seems to be OK
这篇关于jade html转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文