呈现返回 html 代码以显示为视图

rendering returned html code to be shown as a view

所以我将当前日期保存在 cookie 中,并尝试使用模板引擎在 html 网页中显示此 cookie 的值。问题是当我发送包含日期的新模板时,我得到一个 HTML 文本而不是视图。

router.get('/', (req, res) => {
    let template = fs.readFileSync(indexFile, 'utf8');
    var dataToShow = {"cookie_data": 'Letzte Besuch: ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()};
    template = mustache.render(template, dataToShow);
    res.send(template);
})

在我的 HTML 页面中,我有以下内容:

<p>{{cookie_data}}</p>

我希望有一个视图而不是 html-code

请尝试使用

<p>{{{cookie_data}}}</p>

请参考此文档:http://handlebarsjs.com/#html-escaping

请使用

res.render('page', 'params')