I
I
Isaac Clark2016-04-26 15:35:06
JavaScript
Isaac Clark, 2016-04-26 15:35:06

Handlebars: how to connect one template inside another and write a helper to it?

Hello.
There is a .hbs template that includes the page header

{{partial "header"}}
<div>...</div>

Can you please tell me how to write a helper that will parse this template and connect a helper to it?
let template = Handlebars.registerHelper('partial', function (html, context) {
 // здесь нужно обрабатывать паршлс? 
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2016-04-27
@bingo347

More or less like this:

Handlebars.registerHelper('partial', function(template, context) {
    if(!Handlebars.templates[template]) return '';
    return new Handlebars.SafeString(Handlebars.templates[template](context));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question