Search code examples
node.jsexpressejsconnect-flash

connect-flash message with HTML?


I would like to include a link in the text of a connect-flash message:

JS

req.flash("registerMessage", "Sorry, the User ID you chose is already in use. Please choose another. If you have already registered and need assistance logging in, <a href=\"http://www.example.com/support/\">contact support</a>");

EJS

<% if (message.length > 0) { %>
  <div class="alert alert-danger"><%= message %></div>
<% } %>

Result

<div class="alert alert-danger">Sorry, the User ID you chose is already in use. Please choose another. If you have already registered and need assistance logging in, &lt;a href=&quot;http://www.example.com/support/&quot;&gt;contact support&lt;/a&gt;.</div>

Is there a way to prevent flash from escaping the HTML characters so I can display links in my messages?


Solution

  • You can use :

    <%- message %> 
    

    to output unescaped HTML