js部分/子模板输出未定义
Dust js partials / child templaes output undefined
我使用nwjs和dust.js。父模板按预期工作,但如果我尝试加载子(部分)模板,输出是未定义的。我错过了一些让孩子/部分模板工作吗?谢谢。
<div id="output"></div>
<script>
const dust = require('dustjs-helpers');
</script>
<!-- Because I can't figure out why require(./dist/templates) errors dust undefined. -->
<script type="text/javascript" src="./dist/templates.js"></script>
<script type="text/javascript">
let templateName = 'src/templates/anotherTemplate',
data = {heading: "This is a heading", article: "Blah blah blah."};
dust.render(templateName, data, (err, out) => {
console.log(out);
document.getElementById('output').innerHTML = out;
});
</script>
模板:
someTemplate。尘埃:(父)
<h1>{heading}</h1>
<p>{article}</p>
{+someBlock/}
anotherTemplate。尘埃:(子/部分)
{>someTemplate/}
{<someBlock}
My custom block content.
{/someBlock}
编译模板:(用dustc - ./node_modules/dustjs-linkedin/bin/dustc ./src/templates/*编译。- 0 ./dist/templates.js)
(function(dust){dust.register("src'/templates'/anotherTemplate",body_0);var blocks={"someBlock":body_1};function body_0(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.p("someTemplate",ctx,ctx,{});}body_0.__dustBody=!0;function body_1(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.w("My custom block content.");}body_1.__dustBody=!0;return body_0}(dust));
(function(dust){dust.register("src'/templates'/someTemplate",body_0);function body_0(chk,ctx){return chk.w("<h1>").f(ctx.get(["heading"], false),ctx,"h").w("</h1><p>").f(ctx.get(["article"], false),ctx,"h").w("</p>").b(ctx.getBlock("someBlock"),ctx,{},{});}body_0.__dustBody=!0;return body_0}(dust));
您包括{>someTemplate/}
,但是您已经用不同的名称注册了模板:src/templates/someTemplate
。
如果您希望Dust注册没有src/templates
前缀的模板,将--pwd
参数传递给Dust:
./node_modules/dustjs-linkedin/bin/dustc ./src/templates/*.dust -o ./dist/templates.js --pwd=src/templates
相关文章:
- Node.js/Express未输出console.log,highcharts.js给出未定义的错误
- JS函数只返回未定义的数据,但alert输出正确的数据
- '未定义'当需要模块时输出
- 具有中文字符但输出的JSON.parse数据变为“;未定义”;
- 为什么我的输出未定义
- IE9中的有效输出,但IE7/IE8中的未定义输出
- 当在 Javascript 中使用许多 for 循环时,输出是未定义的
- 它无法正常工作,它输出未定义
- Vue.js 使用 Vuex 和自定义组件,@click方法输出未定义
- 带有Ajax的JavaScript和HTTP请求输出未定义的显示2
- 对象实例为其输出“未定义”'s原型'的属性.为什么?
- 输出未定义
- FileReader输出未定义
- 使用数组.Push输出未定义
- 从函数调用返回对象的函数输出未定义
- js部分/子模板输出未定义
- Angular UI掩码格式化输出未定义
- jsPdf输出未定义
- 对变量的访问输出未定义
- 为什么输出未定义