It seems that if Jade (Pug) cannot resolve a variable it treats it as not set.
Is there a possibility to make it fail during rendering of the template?
Controller code:
exports.index = function (req, res) {
res.render('index', {})
};
Template code:
extends layout
block content
p Value is "#{val}"
Result:
<p>Value is ""</p>
This does not detect bugs early and thus I would like Jade to throw an exception when something like this happens. Is it possible ?
You should be able to use conditionals for this like so:
block content
if val
p Value is "#{val}"
else
p Value is undefined
or
block content
if val !== ""
p Value is "#{val}"
else
p Value is undefined
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.