Skip to content

It's not possible to create a helper function for dynamic partial names. #36

@taron96

Description

@taron96

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions