我正在使用dust.js模板引擎。主模板包含一个部分,问题是dust.js对包含的模板文件的每一行进行裁剪。
例如,主要模板是:
<h1>{header}</h1>
{>dust_cnt /}dust_cnt.dust是:
<div>
This is
the content
</div>我呈现的响应是:res.render(‘dust_TEMplate.DUSE’,{header:'TEST OK'});
输出中This is和the content之间没有空格的问题。因此,输出看起来如下:
TEST OK
This isthe content,我不能通过放置{n}或另一个分隔符来更改所有内容,而且我认为没有任何理由这样做。
在http://linkedin.github.com/dustjs/上,我发现了下面的备注GH- 166 - Added trimming of white spaces in dust templates configuration in the dust.compile ( default option is still true)。但无法找到设置选项以避免修剪的方法吗?
我如何使dust.js以我所期望的方式呈现它(有空格)?
提前谢谢你!
发布于 2013-04-03 08:43:01
好的,我找到了解决方案:)。在深入了解源代码+检查尘埃的GitHub上的问题之后,我决定使用以下方法来防止模板节点的格式设置:
dust.optimizers.format = function(ctx, node) { return node };(也在https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#controlling-whitespace-suppression上)
默认行为非常危险--正如它在GitHub上提到的那样,它可能导致严重的问题,例如:
<script>
//this will alert "test"
alert("this is test");
</script>将以下列形式呈现:
<script>//this will alert "test" alert("this is test");</script>发布于 2013-04-02 17:43:57
这很奇怪,我知道您不想编辑模板文件。但是,您可以通过在行尾添加一个空格,以一种不那么难看的方式解决这个问题:
<div>
This is < add space here
the content
</div>只是在这种情况下,你无法找到真正的解决方案。
https://stackoverflow.com/questions/15769861
复制相似问题