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

Loading pre-compiled templates is broken when using AMD and v1.1 #563

Closed
zvikico opened this issue Jun 26, 2013 · 8 comments
Closed

Loading pre-compiled templates is broken when using AMD and v1.1 #563

zvikico opened this issue Jun 26, 2013 · 8 comments
Milestone

Comments

@zvikico
Copy link

zvikico commented Jun 26, 2013

In the current master, v1.1, the library loading is adapted to using AMDs (I use require.js). When using an require.js, for example, the Handlebars is no longer a global var. This works OK if you've used require.js properly, since you are supposed to start your module with a block that looks like this:

define([ "handlebars"], function( Handlebars ) {
     ...
});

This works well. But, compiled templates are not defined that way. The code assumes templates are global. Here's a sample code I use:

define([ "handlebars"], function( Handlebars ) {

   Handlebars.registerHelper(...);

   require(["js/templates/temp1.js", "js/templates/temp2.js"], function() { 
        ...
   }
});

The helper registration works, because Handlebars is defined. However, the templates loading failed because it is not. I could add something like:

   window.Handlebars = Handlebars;
   require(["js/templates/temp1.js", "js/templates/temp2.js"], function() { 
        ...
   }

And that would fix the problem. But that's not really backwards compatible...

@blessanm86
Copy link
Contributor

If your templates are precompiled, you just need to require the js file and
the template should be accessible at Handlebars.templates.temp1
Is this what you tried?
On Jun 26, 2013 8:09 PM, "Zviki Cohen" [email protected] wrote:

In the current master, v1.1, the library loading is adapted to using AMDs
(I use require.js). When using an require.js, for example, the Handlebars
is no longer a global var. This works OK if you've used require.js
properly, since you are supposed to start your module with a block that
looks like this:

define([ "handlebars"], function( Handlebars ) {
...});

This works well. But, compiled templates are not defined that way. The
code assumes templates are global. Here's a sample code I use:

define([ "handlebars"], function( Handlebars ) {

Handlebars.registerHelper(...);

require(["js/templates/temp1.js", "js/templates/temp2.js"], function() {
...
}});

The helper registration works, because Handlebars is defined. However, the
templates loading failed because it is not. I could add something like:

window.Handlebars = Handlebars;
require(["js/templates/temp1.js", "js/templates/temp2.js"], function() {
...
}

And that would fix the problem. But that's not really backwards
compatible...


Reply to this email directly or view it on GitHubhttps://github.com//issues/563
.

@zvikico
Copy link
Author

zvikico commented Jun 26, 2013

Yeah. Exactly. But the pre-compiled template syntax does not use AMD.

@blessanm86
Copy link
Contributor

There is an amd flag for that. This is the command that I normally use

Handlebars templates/>pagetemplates.js -a -e html

This is supported in the latest precompiler. Some options are not in the
doc. I've sent a pull request(#555) to include them.
On Jun 26, 2013 8:25 PM, "Zviki Cohen" [email protected] wrote:

Yeah. Exactly. But the pre-compiled template syntax does not use AMD.


Reply to this email directly or view it on GitHubhttps://github.com//issues/563#issuecomment-20053083
.

@zvikico
Copy link
Author

zvikico commented Jun 26, 2013

Good. I'll try it. So it could be a documentation issue. There should be some note in the changelog or docs explaining the steps necessary to move to full AMD support.

@kpdecker
Copy link
Collaborator

kpdecker commented Jul 1, 2013

@zvikico Did the flag work for you?

@zvikico
Copy link
Author

zvikico commented Jul 1, 2013

Yes, it does.

I'm glad to see AMD support is being introduced to Handlebars.js. I've been a huge fan of require.js for a long time now and this is a very important step for Handlebars.

Still, it means that 1.1 won't be a drop-in replacement for many people out there. That's something to consider.

@kpdecker
Copy link
Collaborator

Heads up: under 1.1 we moved to ES6 modules which now require default dereference for AMD loaders. This is resolved by e9350f2 but templates should be recompiled when upgrading to the formal 1.1 release that I hope to get out shortly.

@kpdecker
Copy link
Collaborator

kpdecker commented Nov 4, 2013

Released in 1.1.0

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