last day (14 days later) » 

1:48 AM
0
A: Access flash messages from Jade in Express 4

xShiraseI see you're using a middleware to access the messages in all the views. It's perfectly fine, but you have to declare it before your routes definition : // send errors to page if any. app.use(function(req, res, next){ res.locals.success_messages = req.flash('success_messages'); res.loca...

 
Don't I have to change this up aswell in that case? res.render('index'); to res.render('index', {message: ""});? Right now I'm getting undefined. Redirecting to / when I try to register with invalid credentials.
 
Sorry, ignore my previous answer, I didn't realize that your code was scrolling down :-) See edit, you should be fine with just switching the order of your app.use
 
Oddly, I am getting 404 not found now when accessing GET /. EDIT: Nevermind, moved it after the 404 app.use aswell!
 
cool, don't forget to change the name to 'error_messages'
 
This solved the issue, however, there's one more thing. #{error_messages} is now escaping HTML. So the actual message: <strong>Emailhere</strong> is not a valid email address! is displayed exactly like that, with the <strong> tags as plain text.
 
1:48 AM
you should keep display and content separate. put your strong tags in the template and send just the message. see edit
 
That requires me to flash a object though. For example, I input test123 as email, the message back would be <strong>test123</strong> is not a valid email address!. Is it possible to flash an object?
 
are you there?
 
Sorry!
Yeah, got stuck in this mess :P
Thank you for your time though! I greatly appreciate it.
 
try to use !{error_messages} in jade to display your html tags
instead of #
let me know if it works so I can edit my answer
 
Yeah, that worked like a charm!
So, conclusion: # = escape HTML, ! = non-escaping!
I'm thinking of making this MVC, as it's going to be quite a large project...
 
1:52 AM
cool! glad I could help
 
Much appreciated! Thank you!
 

last day (14 days later) »