Nodejs EJS helper functions?

Yes, in Express 3 you can add helpers to app.locals. Ex: app.locals.somevar = “hello world”; app.locals.someHelper = function(name) { return (“hello ” + name); } These would be accessible inside your views like this: <% somevar %> <% someHelper(‘world’) %> Note: Express 2.5 did helpers differently.

Passing an object to client in node/express + ejs?

In Node.js: res.render(‘mytemplate’, {data: myobject}); In EJS: <script type=”text/javascript”> var rows =<%-JSON.stringify(data)%> </script> SECURITY NOTE : Don’t use this to render an object with user-supplied data. It would be possible for someone like Little Bobby Tables to include a substring that breaks the JSON string and starts an executable tag or somesuch. For instance, in … Read more

How to escape HTML in node.js EJS view?

You are escaping the value correctly by using: <%= bloglist[i].Text %> If you want to allow HTML to be rendered, then you want an “unescaped” value. To do that use the following: <%- bloglist[i].Text %> All I did was replace the equal (=) with a dash (-). Reference: https://github.com/visionmedia/ejs/tree/0.8.3#features

how to include a template with parameters in EJS?

@Naeem Shaikh solution works. Though include also gives you more intuitive way of including a partial template and also passing context variables to that as found in documention section of ejs. <ul> <% users.forEach(function(user){ %> <%- include(‘user/show’, {user: user}); %> <% }); %> </ul>