New line in express.js message

强颜欢笑 提交于 2020-01-05 04:09:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!