-
Notifications
You must be signed in to change notification settings - Fork 9
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
handlebars partials support is not convenient. #9
Comments
Hey Larry, could you provide an example of what you mean? Thanks! |
Hi @davis , I mean this plugin should be able to parse handlebar template and automatically register partials. for example. I have below handlebar template. the plugin should extract /path/to/myPartial out and automatically register it. requirejs-handlebar-plugin works that way. It's the same thing for helper. Not sure If i am making sense. Thanks.
|
This is something I recently dealt with in a custom handlebars plugin. Here's a basic overview of how it works:
export function fetch(load, fetcher) {
return fetcher(load)
.then(templateSrc => {
let partials = findPartials(Handlebars.parse(templateSrc));
// adds partials to dependencies
return templateSrc;
});
}
load.metadata.deps = partials.map(p => `${partial}!hbsTmpl`);
let depRequires = load.metadata.deps.map(d => `require("${d}");`;
load.source = `
${depRequires.join('\n')}
require('${handlebarsRuntimePath}').registerPartial(${load.name}, Handlebars.template(${precompiled});
`; It's rough, but I could fold it up into a PR if there's interest. There's a few points that are definitely sub-par that will need some work before it's really "merge ready", though. |
@BennettJames would definitely be open to PRs! |
Hi @davis , this is a great SystemJs plugin. Really love it. but its handlebar partials support is not really convenient. because for each partials, you have to manually register it beforehand. So how can I make it automatically register partials while parsing handlebars template? I know require-handlebars-plugin does this type of things. (https://github.com/SlexAxton/require-handlebars-plugin/blob/master/hbs.js). Thanks for the great job.
The text was updated successfully, but these errors were encountered: