问题
Is it possible to make a new line in the message notification?
"\n" or "\r\n" just disappear but there's no new line set.
I also tried
var endOfLine = require('os').EOL;
instead of \n. Doesn't work sadly.
res.render('settings.ejs', {
user: req.user,
isAuthenticated: true,
message: 'Changed User(s):' + changearray + '\n(Notice: You can\'t affect Users with higher Settingrights.)'
});
Probabbly a stupid/easy question but I don't get it working... Thanks in advance.
回答1:
You can use html tags. The reason why they are not getting displayed is because I suppose you must be using escaped
text. You need to use the unescaped
syntax if you want to render the tags in your html string:
res.render('settings.ejs', {
user: req.user,
isAuthenticated: true,
message: 'Changed User(s):' + changearray + '<br />(Notice: You can\'t affect Users with higher Settingrights.)'
});
Here's how to display unescaped text in your view:
<%- message %>
来源:https://stackoverflow.com/questions/38456714/new-line-in-express-js-message