Giter Club home page Giter Club logo

Comments (8)

fiznool avatar fiznool commented on June 3, 2024

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.

monzou avatar monzou commented on June 3, 2024

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.

emiliomg avatar emiliomg commented on June 3, 2024

monzou's solution works fine for us, thank you!

from grunt-contrib-handlebars.

monzou avatar monzou commented on June 3, 2024

😃

from grunt-contrib-handlebars.

emiliomg avatar emiliomg commented on June 3, 2024

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.

creynders avatar creynders commented on June 3, 2024

@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.

paynecodes avatar paynecodes commented on June 3, 2024

@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.

TheBox193 avatar TheBox193 commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.