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

Is there anyway to precompile handlebars helpers as well? #8

Closed
avidal opened this issue Oct 12, 2012 · 8 comments
Closed

Is there anyway to precompile handlebars helpers as well? #8

avidal opened this issue Oct 12, 2012 · 8 comments

Comments

@avidal
Copy link

avidal commented Oct 12, 2012

Any chance for a helpers filepath, which will be mixed in when precompiling?

@tkellen
Copy link
Member

tkellen commented Oct 12, 2012

I'm not sure I understand what you're asking, but you can control the filepath of your precompiled templates by using the option processName:
https://github.com/gruntjs/grunt-contrib-handlebars#processname-function

@avidal
Copy link
Author

avidal commented Oct 12, 2012

What I mean is if I have a helpers.js file that contains a bunch of calls to Handlebars.registerHelper, I'd be a bonus if the precompilation stage could effectively just concat that right into the precompiled templates.

Admittedly, it's not a big deal and I could do it by using a concat task that concatenates my helpers and the precompiled template file myself; so feel free to close the issue if you'd like.

@tkellen
Copy link
Member

tkellen commented Oct 12, 2012

Ahh, ok. Yes, that's definitely something that should be handled with the concat task

@tkellen tkellen closed this as completed Oct 12, 2012
@c4urself
Copy link

@avidal I'm running into this issue -- would you mind sharing exactly how you went about adding helpers to your precompiled templates.js?

@avidal
Copy link
Author

avidal commented Dec 20, 2012

@c4urself I didn't add it to the precompiled templates.js, I just created a new helpers.js which I load after I load the runtime and before I load the templates:

// helpers.js
(function(Handlebars) {

  Handlebars.registerHelper('foo', function() {});

}(window.Handlebars));

@c4urself
Copy link

@avidal Thanks for the reply! I had gotten it working as well -- I was using an older Handlebars version which was causing some errors.

@empz
Copy link

empz commented Mar 27, 2014

@avidal I'm not being able to use custom helpers in my precompiled templates. I'm doing as you suggest, first runtime, then helpers, then compiled templates.
I got an error when trying to use the template with a context.
See this for more info: http://stackoverflow.com/questions/22700297/precompiling-handlebars-template-with-custom-helpers

@andycbriggs
Copy link

I recently wanted to do this and modified grunt-contrib-handlebars to pre-compile helpers into the same file (commit: andycbriggs@6494373).

You pass the helpers to the options hash, here I keep mine in an external file as a node module.

options: {
  helpers: require('./lib/templateHelpers.js')
}

That commit is a quick try and by no means tested for all cases, but would this be something that people would be interested in?

andycbriggs referenced this issue in andycbriggs/grunt-contrib-handlebars Apr 2, 2015
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

5 participants