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

Handlebars Namespace config #69

Open
Kerrick opened this issue Sep 6, 2013 · 3 comments
Open

Handlebars Namespace config #69

Kerrick opened this issue Sep 6, 2013 · 3 comments

Comments

@Kerrick
Copy link

Kerrick commented Sep 6, 2013

I really appreciate the namespace config option, so that I can put my templates in (e.g.) MyApp.Templates. However, I've also got my Handlebars namespaced as MyApp.Handlebars. Is there a way to make the generated JS templates obey that namespace? As of now, they look something like this (for a simple <h1>Hello, World.</h1> template):

this["MyApp"] = this["MyApp"] || {};
this["MyApp"]["Templates"] = this["MyApp"]["Templates"] || {};

this["MyApp"]["Templates"]["consumer/sweeps/test.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};



  return "<h1>Hello, World.</h1>\n\n";
  });

Note the explicit call to Handlebars. Can I change that to (e.g.) MyApp.Handlebars so it looks something like this?

this["MyApp"] = this["MyApp"] || {};
this["MyApp"]["Templates"] = this["MyApp"]["Templates"] || {};

this["MyApp"]["Templates"]["consumer/sweeps/test.hbs"] = MyApp.Handlebars.template(function (MyApp.Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, MyApp.Handlebars.helpers); data = data || {};



  return "<h1>Hello, World.</h1>\n\n";
  });
@trojjer
Copy link

trojjer commented Oct 4, 2013

I would also like to see this config option to avoid namespace conflicts. Trying to wrap my brain around Grunt and RequireJS, so much more of a headache it seems than Brunch!

Anyway, I'm stuck trying to move a project from compile-every-time Handlebars templates within script blocks (loaded via jQuery). If I leave the compiled output as-is, Handlebars is undefined within the AMD wrapper and execution fails at this point.

When I set wrapped to false in my Gruntfile options for grunt-contrib-handlebars, I can render templates if I call Handlebars.template() upon rendering -- but that is a bit cumbersome. I can also get the templates to work with this wrapping on by removing/renaming the first Handlebars arg from the AMD wrapper in the compiled templates file. The second definition of Handlebars within the inner template function then points to the correct requirejs.config path for the module (which is resolved as a bower component for the project). Unfortunately, any changes to the compiled output is obviously obliterated upon recompilation.

@lazd
Copy link
Contributor

lazd commented Aug 3, 2014

See my comment here, #96 (comment), it would solve this issue.

@jd327
Copy link

jd327 commented Dec 5, 2014

+1

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

Successfully merging a pull request may close this issue.

4 participants