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

Registered Partial cannot be found #1201

Closed
Vamirs opened this issue Mar 16, 2016 · 2 comments
Closed

Registered Partial cannot be found #1201

Vamirs opened this issue Mar 16, 2016 · 2 comments

Comments

@Vamirs
Copy link

Vamirs commented Mar 16, 2016

Hello,

after using handlebars.js again for a while now(4.0.5) drives me in an error I cannot really debug:

I register partials, in the developer tools of chrome I also get from Handlebars.partials:

Handlebars.partials Object {hotel: "<tr> ↵ <td class="text-center"><i class="fa fa-… <td>Test User<br />Test User 2</td> ↵</tr>", flight: "<tr> ↵ <td class="text-center"><i class="fa fa-… <td>Test User<br />Test User 2</td> ↵</tr>"}

So well, the partial is registered. But I cannot use it, telling me: handlebars.js:518 Uncaught Error: The partial flight could not be found

How I register the partials(both template and partials are gotten from files)

`function buildContent(data) {
var customerData = data;
var templateScript = '';
$.ajax({
type: "GET",
url: "templates/customerData-en.html",
dataType: "html",
success: function (data) {
templateScript = data;

        var renderedTemplate = Handlebars.compile(templateScript);

        var partialsDir = '/templates/partials/';
        var partials = [
            "flight",
            "hotel"
        ];

        $(partials).each(function (index, name) {
            $.get(partialsDir + name + '.html', function (data) {
                Handlebars.registerPartial(name, data);
            });
        });


        $("#wrapper").html(renderedTemplate(customerData));
    }
});

}`

works all fine without trying to call a partial in the template with {{> partialname, in that case flight}}

Is there anything changed in handlebars in Version 4 I do not find? Or is this a bug?

Or maybe am I just du dumb right now?

Thanks in advance

@kpdecker
Copy link
Collaborator

Your partials are loaded async and are unlikely to exist at the time that
the template is rendered. You'll need to either defer the template
rendering until those are loaded or compile the partials into the primary
setup logic.
On Wed, Mar 16, 2016 at 10:31 AM Vamirs [email protected] wrote:

Hello,

after using handlebars.js again for a while now(4.0.5) drives me in an
error I cannot really debug:

I register partials, in the developer tools of chrome I also get from
Handlebars.partials:

Handlebars.partials
Object {hotel: "
↵ <i class="fa fa-… Test User
Test User
2
↵", flight: "
↵ <i class="fa fa-… Test User
Test User
2
↵"}

So well, the partial is registered. But I cannot use it, telling me:
handlebars.js:518 Uncaught Error: The partial flight could not be found

How I register the partials(both template and partials are gotten from
files)

`function buildContent(data) {
var customerData = data;
var templateScript = '';
$.ajax({
type: "GET",
url: "templates/customerData-en.html",
dataType: "html",
success: function (data) {
templateScript = data;

    var renderedTemplate = Handlebars.compile(templateScript);

    var partialsDir = '/templates/partials/';
    var partials = [
        "flight",
        "hotel"
    ];

    $(partials).each(function (index, name) {
        $.get(partialsDir + name + '.html', function (data) {
            Handlebars.registerPartial(name, data);
        });
    });


    $("#wrapper").html(renderedTemplate(customerData));
}

});

}`

works all fine without trying to call a partial in the template with {{>
partialname, in that case flight}}

Is there anything changed in handlebars in Version 4 I do not find? Or is
this a bug?

Or maybe am I just du dumb right now?

Thanks in advance


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#1201

@nknapp
Copy link
Collaborator

nknapp commented Apr 5, 2020

Closing due to inactivity.

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

3 participants