-
Notifications
You must be signed in to change notification settings - Fork 126
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
Partials with runtime.js #49
Comments
I don't personally use this plugin any longer, but @pdokas might. |
I do, but I’m unclear about what exactly you’re wondering @danactive. Generally speaking, Handlebars will compile your partials like normal templates and where other templates invoke a partial the compiler will generate a line similar to: stack1 = self.invokePartial(partials['detail-view'], 'detail-view', depth0, helpers, partials, data); From this point, as long as you have all of the needed templates and the Handlebars runtime loaded you should be good to go. Could you ask a more specific question, @danactive? |
I haven't tried your exact example syntax, but when I look at the handlebars-runtime.js code I see compile method is required https://raw.github.com/wycats/handlebars.js/1.0.0-rc.3/dist/handlebars.runtime.js My code snippet is |
@pdokas I see my precompiled templates have similar code as your sample. What I'm asking about is how do I use the template from the client side after the precompile has occurred. I currently register my partial But I get an error message when I try to use the master template I'm getting this error message -=Dan=- |
@danactive Sorry about the delay in getting back to you, thanks for the reminder to do so! What I'm seeing is that you’re not precompiling your partials which handlebars-runtime.js requires you to do. What leads me to believe this is that your partials are being registered like this: Handlebars.registerPartial("listingCount", JST["./Templates/ListingCount.html"]); Whereas a successful compilation of a partial should be generated out to something like: Handlebars.registerPartial("PARTIAL_NAME", Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
... Or if you have Handlebars.registerPartial("PARTIAL_NAME", this["YOUR_NAMESPACE"]["PARTIAL_NAME"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { I personally use a config like this: options: {
namespace: 'Templates',
wrapped: true,
partialsUseNamespace: true,
partialsPathRegex: /\/partials\//,
partialRegex: /.*\.handlebars$/,
processName: function(fileName) {
var bits = fileName.split('/');
return bits[bits.length - 1].replace('.handlebars', '');
},
processPartialName: function(fileName) {
var bits = fileName.split('/');
return bits[bits.length - 1].replace('.handlebars', '');
}
},
files: {
expand: true,
cwd: 'common/templates/',
src: ['**/*.handlebars'],
dest: 'build/js/templates/',
flatten: true,
ext: '.js'
} |
Okay, I'm starting to see where you're going. You're bypassing the missing runtime.js compile method by defining your own function But what code would be inside that anonymous function? -=Dan=- |
I would say it’s more that you can use grunt-contrib-handlebars to compile your partials ahead of time, just like a normal function. The compiled function – beginning with |
@pdokas nice, was about asking a kind of same question, but your last code-snippet solved all my questions and problems. Thank you! Works wonderfully now 👍 |
This issue thread was super helpful in explaining how to use partials in run time only. |
Do you have sample code on how-to use partials with the handlebars-runtime.js?
The text was updated successfully, but these errors were encountered: