Comments (8)
I have this same problem.
If you don't mind calling the template function manually in your code, you can pass the option wrapped: false
to stop the function from being wrapped in a Handlebars.template()
call.
handlebars: {
compile: {
options: {
namespace: 'SST',
processPartialName: function (filePath) {
var pieces = filePath.split("/");
return pieces[pieces.length - 1];
},
amd: true,
wrapped: false
},
files: {
"source/javascripts/templates/thing.js": "source/templates/thing.hbs"
}
}
}
define(['handlebars'], function (Handlebars) {
this["SST"] = this["SST"] || {};
this["SST"]["source/templates/thing.hbs"] = function (Handlebars, depth0, helpers, partials, data) {
this.compilerInfo = [2, '>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers;
data = data || {};
return "<div class=\"notfoundevents\"><p>No events for you</p></div>";
};
return this["SST"];
});
from grunt-contrib-handlebars.
I got a same problem.
For now, I solve this by init
function.
shim: {
handlebars: {
exports: 'Handlebars',
init: function() {
this.Handlebars = Handlebars;
return this.Handlebars;
}
}
}
from grunt-contrib-handlebars.
monzou's solution works fine for us, thank you!
from grunt-contrib-handlebars.
😃
from grunt-contrib-handlebars.
What I do not understand is: why does it work?
In says in the RequireJS API Doc:
In RequireJS 2.0.*, the "exports" property in the shim config could have been a function instead of a string. In that case, it functioned the same as the "init" property as shown above. The "init" pattern is used in RequireJS 2.1.0+ so a string value for exports can be used for enforceDefine, but then allow functional work once the library is known to have loaded.
So, if I understand it correctly, the "init" works like the "exports", but it is a function rather than a string. But doesn't the "exports" do just that? Register "Handlebars" globally?
I think I am missing something, so please help me. Why does your solution work?
from grunt-contrib-handlebars.
@monzou thank you! I've been hunting this one down for days. Wasn't entirely sure which grunt task was producing the bug. And to be honest I'm not entirely sure it is grunt-contrib-handlebars. I had to use your solution for Marionette as well, so I'm starting to think this is a bug with grunt-contrib-requirejs or maybe requirejs itself...
Thanks again!
from grunt-contrib-handlebars.
@monzou Thank you so much. It works!
@creynders I don't believe it is a grunt-contrib-handlebars problem. I just came across this same issue, and my project does not have it installed yet.
@emilio-janzen I too, would love to know why this works.
from grunt-contrib-handlebars.
Added to my config.js for require and worked like a charm. Resolved my error Uncaught TypeError: Cannot call method 'template' of undefined
for now. -- Thanks
from grunt-contrib-handlebars.
Related Issues (20)
- Precompiled JST in <=IE9 HOT 2
- Partial's context is undefined
- Add support for Handlebars 3.x HOT 17
- Allow to specify Handlebars version HOT 1
- Add UMD support HOT 2
- How to add Custom Helpers HOT 2
- AMD requires 'handlebars' instead of just 'handlebars.runtime' HOT 1
- How to add runtime code to output file?
- handlebars with grunt HOT 1
- Update to Handlebars 4.*, precompiled templates not usable with latest bower version HOT 20
- Using commonjs:true generates incorrect JS code (0.10.2) HOT 2
- Declaring multiple AMD dependencies with a function
- 0.11? HOT 2
- Is "style" a keyword of grunt-contrib-handlebars
- options.separator gets normalized HOT 1
- Tests aren't passing with the current master branch HOT 1
- Can be this used from a file watcher?
- Still Maintained?
- Arbitrary Code Execution
- Does not return Template when Pre-Processing as a partial using AMD
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-contrib-handlebars.