javascript - jade 中无法解释的 "<"和双输出包括

标签 javascript node.js express include pug

我正在重构我的页面以具有动态包含,在服务器上预呈现它们,并将它们传递给 res.render()

但是现在,有<>出现在页面上,包含被呈现两次,我无法理解。

routes/tips.js

// ...

router.get('/addition/:number', function(req, res) {
    console.dir(renderTemplate(makePath('add/add' + req.params.number))); // shows just what i want, without extra characters
    res.render('tips/tipsLayout', {content: renderTemplate(makePath('add/add' + req.params.number))});
    // at this point, 'content' is definitely correct.
});

// ...

this is correct

tipsLayout.jade

extends ../layout
block content
    .wrapper.col-xs-12.col-md-12.col-lg-10.col-lg-offset-1
        h1= title

        a(href='/tips/', data-i18n="buttons.back")
        p(data-i18n="markup.tipsHeading")

        block extraJS
            script(src='/javascripts/tips.js', type='text/javascript')

        include tipsMenu.jade

        .tipContent
            #{content}  // here i want to insert pre-rendered 'content'

tips/add/add0.jade (这是预渲染的)

- var path = "[html]hints.+.0."

h1(data-i18n=path + "0")
.tipsFrame
    .tipsText
        p(data-i18n=path + "1")
        p(data-i18n=path + "2")
        p(data-i18n=path + "3")
    .tipsExample
        p(data-i18n=path + "4")
        p(data-i18n=path + "5")
        p(data-i18n=path + "6")

html 输出:

// ...

<div class="tipContent">   // so it looks like it is something inside 'content' after all..?
    "<"
    <h1 data-18n="[html]hints.+.0.0">Addition from left to right (1)</h1>
    <div class="tipsFrame">...</div>
    ">"
    <!--<h1 data-i18n="[html]hints.+.0.0"-->     // note the comment here...(where does that come from?)
    <div class="tipsFrame">...</div>
    ">"
</div>

// ...

之前一切正常,提示正常包含在内 extend/block

this is how it looks

更新

我在想这可能与 block content 有关和 #{content}具有相同的名称,但我更改了后者并且仍然是相同的输出。

更新2 & 解决方案

嗯..看起来像#{content}必须是 !{content} ....

最佳答案

开始吧..

#{content} => !{content} ...

突然之间,所有的错误都消失了

关于javascript - jade 中无法解释的 "<"和双输出包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34722354/

相关文章:

node.js - 来自 Electron 的 Node 服务的 Windows 通知

javascript - 如何将 ember 添加到 NodeJS 项目中?

javascript - 默认选择剑道组合框

node.js - 在 XLSX 导出期间在工作表的开头插入新行/注释

javascript - 如果数据集名称有多个破折号,如何使用 javascript 设置 div 数据属性?

node.js - 未捕获的类型错误 : Cannot read property getColSpanningList

node.js - 在 node/express + ejs 中将对象传递给客户端?

javascript - 使用express-validator作为Express中间件不起作用

javascript - 如何从另一个 JSON 对象查找值

javascript - onclick 不适用于 Chrome 扩展?