I'm trying to generate a JSP page, and since the template delimiters used by JSP's are the same as the ones used by underscore.
looking at the docs --> .template#wiki-grunt-template-setDelimiters i can see they have a function for that
grunt.template.addDelimiters(name, opener, closer)
Two questions:
- Where would i call that function ?
- Can i change the delimiters only for a
grunt.template.process()
( i have more than one, and for other non .jsp templates, the default delimiters are fine ) ?
Any help is appreciated. Thanks.
I'm trying to generate a JSP page, and since the template delimiters used by JSP's are the same as the ones used by underscore.
looking at the docs --> https://github./gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-setDelimiters i can see they have a function for that
grunt.template.addDelimiters(name, opener, closer)
Two questions:
- Where would i call that function ?
- Can i change the delimiters only for a
grunt.template.process()
( i have more than one, and for other non .jsp templates, the default delimiters are fine ) ?
Any help is appreciated. Thanks.
Share Improve this question edited May 22, 2013 at 8:39 mfreitas asked May 22, 2013 at 8:10 mfreitasmfreitas 2,4053 gold badges32 silver badges42 bronze badges 1- have you tried... escaping the characters, for when it processes the text, it gets printed the way you want? – Gonçalo Vieira Commented May 22, 2013 at 8:50
2 Answers
Reset to default 8from the documentation for grunt.template.process:
The default template delimiters are <% %> but if options.delimiters is set to a custom delimiter name, those template delimiters will be used instead.
that basically would mean that you can call grunt.template.process with the name of the delimiter you added before.
e.g. if you want to use square-brackets as delimiters in one processing step that should do the job:
// first add the new delimiters which you want to use
grunt.template.addDelimiters('square-brackets', '[', ']');
// and use it
grunt.template.process(template, {delimiters: 'square-brackets'});
// and use it with the default delimiters (named 'config')
grunt.template.process(template);
I have exactly the same issue. JSP uses <%= %> tags for its replacement which are also used by grunt. Added a line to overwrite the default setting applied in "https://github./gruntjs/grunt/blob/master/lib/grunt/template.js"
This worked for me:
// REPLACE the default 'config' delimiters
grunt.template.addDelimiters('config', '{%', '%}');
grunt.initConfig(
{ .... });
The delimiter name 'config' must match exactly.