저는 nwjs 및 dust.js를 사용하고 있습니다. 부모 템플릿은 예상대로 작동하지만 자식 (부분) 템플릿을로드하려고하면 출력이 정의되지 않습니다. 하위/부분 템플릿이 작동하기 위해 무언가를 놓치고 있습니까? 감사.더스트 js 부분/하위 templaes 출력이 정의되지 않았습니다.
<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.dust (상위)
<h1>{heading}</h1>
<p>{article}</p>
{+someBlock/}
anotherTemplate.dust (어린이/부분)
{>someTemplate/}
{<someBlock}
My custom block content.
{/someBlock}
컴파일 된 템플릿 : (컴파일 dustc - ./node_modules/dustjs-linkedin/bin/dustc ./src/templates/*.dust -o ./dist/templat es.js) 당신은 {>someTemplate/}
을 포함하고 있지만 다른 이름으로 템플릿을 등록했습니다
(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));
당신이) (당신의 먼지를 필요로 할 경우 comment--를 떠나,이 질문의 요점이 아니므로 템플릿을 컴파일하려면'--cjs'를 사용하여 CommonJS 모듈로 컴파일합니다 (그러나 각 템플릿을 따로 따로 요구해야합니다) : http://www.dustjs.com/guides/rendering/#node-load-precompiled-templates – Interrobang
CommonJS 예제 : https://github.com/linkedin/dustjs/tree/master/examples/commonjs – Interrobang