Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Express.js, how do I make my template display the flash messages?

app.get('/',function(req,res){
    res.render('home'); // I want the template to be able to access the flash message..
});

app.get('/go',function(req,res){
    req.flash("info", "You went GO, and got redirected to home!");
    res.redirect('/');
});

The user first goes to "/go". After that, he will be redirected to "/" and I want a flash message to show as a javascript alert.

How can I do that?

like image 917
TIMEX Avatar asked Nov 28 '22 18:11

TIMEX


1 Answers

Add it as a local to your call to render:

res.render("home", {info: req.flash("info")});

And use it in your template:

#flash
  p= info
like image 182
Todd Yandell Avatar answered Dec 05 '22 13:12

Todd Yandell