view raw
RobKohr RobKohr - 10 months ago 37
Node.js Question

changing type of code wrapper for express + node.js + ejs

In client side ejs I use

[% code %]
instead of
<% code %>
to mark ejs code, but I would like to do the same on the server side with express. On the client side I would do something like
var template = new EJS({text: template_src, type:'['});

Here is my node code:

app.set('view engine', 'ejs');
app.register('.html', require('ejs'));

app.get('/', function(req, res){
res.render('index.html', { title: 'My Site' });

Where do you set the "type" paramater so I can change this option


From the EJS github page:

Custom tags can also be applied globally:

var ejs = require('ejs'); = '{{'; ejs.close = '}}';

The only thing you need to do it copy these lines at the beginning of your Express app and that's that - the change is applied globally (change the open and close tag to whatever you want).

Update for most recent version as of July 20, 2016

As of most recent versions of EJS, it is not possible to use custom tags anymore (see ). All you can do is change delimiters from default % to others ( delimiter option ). There are talks about re-enabling this. See and