ITADN
tj/ejs/Issues

Using "if" to check variable before usage results in Error, Undefined

#90Closednetpoetica 创建于 2012-12-10
N
netpoeticacommented
From the example in the README ``` <% if (user) { %> <h2><%= user.name %></h2> <% } %> ``` This code, in all situations, always results in an error if you don't pass the data to the file. I am trying to use it as, let's say, a report about whether your password was valid - if it wasn't I would render the file with ``` res.render('login', { msg: "Error: your password has too many characters." }); ``` But if the user were going to the login page and it hadn't yet been posted, I would just use: ``` res.render('login'); ``` I could fix this by explicitly sending a msg = null to all routes, but I think that is silly. Any advice on how to properly handle this? My guess is that what I am doing is somehow unconventional in node/ejs. Thanks a bunch, - Keith
关闭于 2012-12-10 13 条评论