Template.hbs
<div>
{{> @partial-block }}
</div>
Then Compile:
Handlebars.compile(fs.readFileSync("./template.hbs", "utf8"))({});
脠rror
/handlebars/runtime.js:266
throw new _exception2['default']('The partial ' + options.name + ' could not be found');
^
Error: The partial @partial-block could not be found
at Object.invokePartial (/handlebars/runtime.js:266:11)
at Object.invokePartialWrapper [as invokePartial] (/handlebars/runtime.js:68:39)
at Object.eval (eval at createFunctionContext (/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:28)
You aren't going to have a partial-block if you are rendering the template directly. Partial blocks are only available when a template is rendered as a partial, i.e. {{#> template}}this block{{/template}}
@kpdecker so there is no way to use the handelbars api to compile a template with a partial-block???
Shouldn't @partial-block
s behave like variables? If they aren't defined, they aren't printed.
jade handles it the same way.
@morgondag I had a similar issue and solved it by using an if statement:
{{#if @partial-block}}
{{> @partial-block }}
{{/if}}
Hope you solved it already though :)
@frederfred It's been a while since you made that comment. But I noticed that your example is not covered by a test-case. I would call it a coincidence that it works like that (it only works, because the compiled partial-block
-partial is stored in the data
-object of the execution context.
Since you have received so many thumbs-up
for this comment, I would suggest that we add a test-case for that example here.
I would accept a PR if anybody wants to write that test.
Most helpful comment
@morgondag I had a similar issue and solved it by using an if statement:
Hope you solved it already though :)