Comments (10)
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}}}
from express-messages.
Good to hear, I'll try and add it to the docs once I get the chance.
from express-messages.
@dalalRohit My error was I forgot to add ( ) at the end of below line of code. :
res.locals.messages = require('express-messages')(req, res)();
in handlebars use : {{{message}}}
to display your message
from express-messages.
bump
from express-messages.
Thanks @di-ego02, can you confirm this work for you @andeersg, @ERPedersen?
from express-messages.
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 :)
from express-messages.
Thanks for the confirmation.
from express-messages.
Works for me too :) I did somewhat the same 👍
from express-messages.
Thanks de-ego02 you solved my issue of using handlebars with express.
from express-messages.
@Gauravkandpal001 Can you show me how did you write the handlebars template code for this? I'm stuck on that only.
from express-messages.
Related Issues (18)
- Doesn't work with Jade Templates HOT 1
- The readme should say how to add messages HOT 5
- Express 3 HOT 9
- move to expressjs org?
- Customizable message template HOT 3
- Custom template not displayed in browser HOT 8
- Custom template collision with express-ejs-layouts module HOT 2
- custom template with EJS HOT 1
- Is this repo still under maintainance ? HOT 5
- Custom templates using handlebars HOT 1
- Problem with != messages()
- how can i use express-messages with handlebars HOT 2
- Can i use it without defining res.locals.messages?
- Doesn't render HTML
- Problem with error message loop pug to ejs
- Not working with ejs
- req.flash() message doesn't work along with res.redirect() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-messages.