jade html转义字符串 [英] jade html escaped string

查看:228
本文介绍了jade html转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与翡翠的问题,我从数据库中取出一个未转义的字符串(这样:



& lt; mo&



此字符串可以包含一些html代码,我将该字符串传递到页面



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



从布局我用!{t.text}标记字符串,但html代码没有渲染,似乎打印纯文本错误在哪里?

解决方案


  1. 我已经设置了默认的 express 应用程序,它使用 / code>作为其模板引擎。


  2. 修改 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}




  1. 结果似乎OK


I have a problema with Jade, I take an unescaped string from db (something like this:

"<mo>&amp"

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?

解决方案

  1. I've set up default express app which uses jade as its template engine.

  2. Modified routes -> index.js to pass some encoded text

router.get('/', function(req, res) {
  res.render('index', { title: 'Express', encodedText: '<mo>&amp' });
});

  1. Modified views -> index.jade to display this text

block content
  h1= title
  p Welcome to #{title}
  p Encoded text !{encodedText}

  1. Result seems to be OK

这篇关于jade html转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆