-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add support for partials #13
Comments
I saw there was #7 which asked for partials, but that was closed without actually adding partial support (right?). Issue #3 mentions someone had a work in progress patch that'd add partials (or dependencies to templates). I think this'd be something that should be supported out of the box without extra dependencies. |
This works with only handlebars.runtime when minified with r.js? Using swag means yet another library dependency and +20 KB minimized download size. |
Yes, it works, I'm using it with r.js. Not 20, but 13kB :) Anyway. You can also use only partial feature, but I think swag has few another useful (everyday) helpers... So it worth to spend 13kB more, I think. |
I actually found a really easy way to do partials without Swag. I'll try to put together a minimal example and send a PR against your README. |
would be cool, thanks in advance! |
Was this issue ever resolved? I am using your implementation and am looking to add partial support myself. |
unfortunately only using https://github.com/elving/swag... |
Yeah, like I said above, there's an easy way to do this without Swag. I just never sent my PR for the simple example as I was unable to get the hbs example project working and was unable to send a minimal PR against the example project. See #17. You can pretty much just directly use
HTH. |
Ok cool I see what you have done here. I was struggling to find how to precompile partials, but I see hbs can do it for me. So taking what you have, I have edited hbs-builder.js to allow me to define a partial in the require string. 'hbs!partial:path/to/templates' and then modify the write output for precompiling requirejs. # hbs-builder.js
var isPartial = (name.substr(0, 8) === 'partial:');
...
if (isPartial) {
write(
"define('hbs!" + name + "', ['handlebars'], function(Handlebars){ \n" +
"Handlebars = Handlebars || this.Handlebars;\n" +
"return Handlebars.registerPartial('" + name.substr(8) + "', Handlebars.template(" + compiled.toString() + ")); \n" +
"});\n"
);
} else {
write(
"define('hbs!" + name + "', ['handlebars'], function(Handlebars){ \n" +
"Handlebars = Handlebars || this.Handlebars;\n" +
"return Handlebars.template(" + compiled.toString() + ");\n" +
"});\n"
);
} # hbs.js
...
if (isPartial) {
onload(Handlebars.registerPartial(name, raw));
} else {
// Just return the compiled template
onload(Handlebars.compile(raw));
} What are your initial thoughts? There is definitely improvement to be made (for one the reputation of code for one) and registerPartial doesn't return anything so I may just return the template instead. |
It'd be great to have support for partial templates.
The text was updated successfully, but these errors were encountered: