Closed andeersg closed 8 years ago
bump
when you utilize this codeapp.use(require('connect-flash')()); app.use(function (req, res, next) { res.locals.messages = require('express-messages')(req, res); next(); });
taken from the documentation here it specifies that you need to invoke res.local.messages in your template, i e <%-messages()%> but in handlebars you can't write js in the curly braces. So we must call res.local.messages before hand, i e res.locals.messages = require('express-messages')(req, res)();
which will return the flash message object! in your handlebar template you access the key 'messages' like this {{{messages}}}
Thanks @di-ego02, can you confirm this work for you @andeersg, @ERPedersen?
Yes, I have done something similar (or exactly the same I see):
app.use(flash());
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});
So I guess we can close this :)
Thanks for the confirmation.
Works for me too :) I did somewhat the same :+1:
Good to hear, I'll try and add it to the docs once I get the chance.
Thanks de-ego02 you solved my issue of using handlebars with express.
@Gauravkandpal001 Can you show me how did you write the handlebars template code for this? I'm stuck on that only.
Is it possible to use this module with handlebars as a view engine?
I'm not sure how to implement it.