Handlebars.js: @partial-block unclear or render bug

Created on 12 Jan 2016  路  5Comments  路  Source: handlebars-lang/handlebars.js

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)

1144

Most helpful comment

@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 :)

All 5 comments

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-blocks 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

janus-reith picture janus-reith  路  3Comments

DylanPiercey picture DylanPiercey  路  7Comments

ustun picture ustun  路  6Comments

LengYXin picture LengYXin  路  3Comments

ShintaroOkuda picture ShintaroOkuda  路  7Comments