Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars Dynamic Partial Block

I have a folder structure like so:

- components/
  - foo/
     - index.js
     - foo.handlebars
     - foo.scss
  - bar/
     - index.js
     - bar.handlebars
     - bar.handlebars

In order to resolve component partials conveniently I provide a helper that will find a correct path, translating bar into components/bar/bar.handlebars. This helper is called getPartialForTemplate.

In my template, I do:

{{> (getPartialForTemplate 'foo') some=props}}

This is fine, but when I need to use the resolved template as a block I come across an issue:

{{#> (getPartialForTemplate 'foo')}}
  <p>Some text here..</p>
{{/WHATGOESHERE???}}

This seems like a syntax flaw in Handlebars, as I'd expect its syntax features to work together. Is there a way to do this?

like image 203
Luke Channings Avatar asked Nov 09 '22 00:11

Luke Channings


1 Answers

There's an open issue on github, the suggested workaround is this:

{{#>( lookup . 'intendedTemplate' )}}
  No template matched for "{{intendedTemplate}}"
{{/undefined}}
like image 103
Ronen Teva Avatar answered Dec 27 '22 03:12

Ronen Teva