【问题标题】:Cradle / Express / EJS convert html to its entitiesCradle / Express / EJS 将 html 转换为其实体
【发布时间】:2011-11-16 22:56:17
【问题描述】:

我在我的博客上使用 Cradle 和 Express 和 EJS。也许我错过了 smth 但其中一些将 html 实体转换为其等价物。

我在 doc.quote 字段中有 html,在这段代码之后它发生了变化

quotesDb.view('list/by_date', {
    'startkey' : {},
    'endkey' : null,
    'descending' : true
}, function(err, res) {
    if (err) {
        r.send();
        return;
    }

    r.partial('quotes', {'quotes' : res}, function(err, str) {
        console.log(str);
        sendResponse('content', str);
    });
});

quotes.ejs:

<% for (var i=0; i<quotes.length; i++) { %>
    <div>
        <%=quotes[i].value.quote%>
    </div>
    <div class="date">
        <%=(new Date(quotes[i].value.ts*1000)).toLocaleDateString()%><% if (quotes[i].value.author) { %>, <%=quotes[i].value.author%><% } %>
    </div>
<% } %>

“res”变量是数组,其中包含带有“content”字段(具有 html)的对象。但是在渲染“str”之后,将“quotes[i].value.quote”符号转换为它的实体,比如
到 &lt ; br>

【问题讨论】:

  • 绝对是 EJS。问题是:如何让它呈现数据而不将其转换为实体。

标签: node.js express ejs cradle


【解决方案1】:

答案在这里找到: http://groups.google.com/group/express-js/browse_thread/thread/f488d19a1604c30e?pli=1

用于转义渲染:

<%=var%>

用于不转义的渲染:

<%-var%>

【讨论】:

    猜你喜欢
    • 2011-03-05
    • 1970-01-01
    • 2010-10-18
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 2016-09-09
    相关资源
    最近更新 更多