wycats / handlebars-site

56 stars 66 forks source link

combining partial block and inline partials #174

Closed carlnc closed 7 years ago

carlnc commented 7 years ago

Should the following code work?

{{#* inline "myPartial"}}
    {{> inline1 }}
    {{> inline2 }}
{{/inline}}

{{#> myPartial}}
    {{#* inline "inline1"}}Incline 1 content{{/inline}}
    {{#* inline "inline1"}}Incline 2 content{{/inline}}
{{/myPartial}}

If I define a proper partial template (ie: myPartial.hbs) the code works, however it appears that mixing both partial block and inline partials is not supported.

nknapp commented 7 years ago

In your example, the line {{#* inline "inline1"}}Incline 1 content{{/inline}} in never evaluated, because there is no {{@partial-block}}-call from myPartial. But it also does not work if there is such a call (see https://jsfiddle.net/9D88g/171/).

The reason is that {{@partial-block}} creates a new context on the stack, to which inline1 and inline2 are added. But when the {{> inline1 }}-call happens, this context has already been deleted because the {{@partial-block}} has ended.

What you can (like in https://jsfiddle.net/9D88g/172/) is defining an inline-partial before calling another one that is using the inline-partial.

You can also replace an existing partial temporarily (which is a little bit nasty, but it works): https://jsfiddle.net/9D88g/173/