Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
taron96 opened this issue Jan 10, 2023 · 0 comments
Open

Comments

@taron96
Copy link

taron96 commented Jan 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant