laravel-handlebars
laravel-handlebars copied to clipboard
It's not possible to create a helper function for dynamic partial names.
I have tried to create a helper function to render dynamic partials in my code.
I've added these in the config/handlebars.php
file:
'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_RUNTIMEPARTIAL,
'partials' => [],
'partialresolver' => function ($cx, $name) {
if (file_exists(resource_path("views/partials/$name.hbs"))) {
return file_get_contents(resource_path("views/partials/$name.hbs"));
}
return '';
},
'helpers' => [
'concat' => function ($path) {
return $path;
},
],
'helperresolver' => function ($cx, $name) {
if ($name === 'concat') {
return (function () {
return '';
});
}
return '';
},
I've added these in the resources/views/home.hbs
file:
<main id="main">
{{#each data }}
{{> (concat this.name) this}}
{{/each}}
</main>
I've made this helper function work, but the partial resolver is not working after the helper function is called.