1

How to globally avoid EJS throw error when context variable is not defined ? I mean a way to set (in middleware?) for example space or null value for all variables not defined. Now i always use on template something like below. Is better way ?

<% if(typeof locals.variable != 'undefined') { %>
 ... 
<% } %>
marioosh
  • 27,328
  • 49
  • 143
  • 192
  • 1
    I think this is a duplicated question from this: http://stackoverflow.com/questions/858181/how-to-check-a-not-defined-variable-in-javascript – rvazquezglez Jan 06 '15 at 17:06

1 Answers1

0

I usually just have a middleware that sets some default values for a particular set of routes via res.locals.variable = undefined; or similar. Then you can successfully check if (variable === undefined) in the template for those routes.

mscdex
  • 104,356
  • 15
  • 192
  • 153