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

Changing Delimiter #350

Closed
danielmahon opened this issue Oct 24, 2012 · 6 comments
Closed

Changing Delimiter #350

danielmahon opened this issue Oct 24, 2012 · 6 comments

Comments

@danielmahon
Copy link

I dont seem to be able to change the delimiter as defined in mustache:

{{=<% %>=}} and then back to <%={{ }}=%>

Im trying to let a 3rd party WYSIWYG generate tags which is possible if I am able to customize the opening and closing tags. Is there another way to do this? Im using handlebars with node.js and express 3.0.

@wycats
Copy link
Collaborator

wycats commented Oct 25, 2012

Unfortunately Handlebars uses a generated parser so it is impossible to change the delimiter at runtime. You could possibly build a custom build of Handlebars by modifying the lexer (https://github.com/wycats/handlebars.js/blob/master/src/handlebars.l) to replace all usages of {{ and }} with your delimiter of choice.

@wycats wycats closed this as completed Oct 25, 2012
@jonschlinkert
Copy link
Contributor

(I mentioned this in another issue, but just in case someone stumbles onto this one) I put this module together to make it easy to use custom delims if anyone is interested. suggestions for improvement or prs are welcome

@little-big-h
Copy link

@jonschlinkert this is a very fragile workaround (it cannot reliably deal with curly braces in the template code). This modified version of your example:

var Handlebars = require('handlebars');
var useDelims = require('handlebars-delimiters');
useDelims(Handlebars, ['<%=', '%>']);
var b = Handlebars.compile('{{ name }}<%= name %>}')({name: 'Jon'});

throws at template compile time.

@jonschlinkert
Copy link
Contributor

Who knew a hack could be fragile ;P any time you have a workaround that is only useful in specific scenarios it will necessarily be fragile in every other scenario. That, and who wants to spend the time to do much more than that? IMO if you need different delimiters for something important, it just makes more sense to use a different engine. Do you have suggestions for a better alternative?

Sent from my iPhone

On Jan 4, 2015, at 8:44 PM, little-big-h notifications@github.com wrote:

@jonschlinkert this is a very fragile workaround (it cannot reliably deal with curly braces in the template code). This modified version of your example:

var Handlebars = require('handlebars');
var useDelims = require('handlebars-delimiters');
useDelims(Handlebars, ['<%=', '%>']);
var b = Handlebars.compile('{{ name }}<%= name %>}')({name: 'Jon'});
throws at template compile time.


Reply to this email directly or view it on GitHub.

@little-big-h
Copy link

So, I guess you effectively demonstrated that it is not that easy to create a clean, robust solution to this problem. While I don't quite agree with you that it makes more sense to use a different engine (they all make tradeoffs) I ended up using swig instead.

@springuper
Copy link

Mustache supports this feature, however, Handlebars doesn't inherit it. It's so bad.

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