Comments (3)
Sorry for the late reply @dearwish, I obviously hadn't set up my GitHub notifications correctly!
Anyway, I think this is a little out of the remit of express-messages
. Personally, when I need some custom templating I bypass it altogether and set up a bit of custom middleware like so:
app.use(function (req, res, next) {
var flash = req.flash()
res.locals.messages = Object.keys(flash).reduce(function (messages, type) {
flash[type].forEach(function (message) {
messages.push({type: type, message: message})
})
return messages
}, [])
next()
})
Now I can access messages
in my jade
templates:
ul.messages
each message in messages
li(class="#{message.type}")= message.message
Or for EJS
:
<ul class="messages">
<% messages.forEach(function (message) { %>
<li class="<%= message.type %>"><%= message.type %></li>
<% }) %>
</ul>
I hope this helps. Of course, if you and others do believe that custom templating should be added to express-messages
then that's something I'll look into.
from express-messages.
Landed in 1225b2d, with thanks to @agraboso.
from express-messages.
Thank you for addressing my question @artcommacode, but I really liked the concept of express-messages
, because the template outcome is very short and clean <%- messages() %>
.
In my case I just customized your module for my local utility to fit the message markup to Zurb Foundation alert boxes.
Of course, this is not the ultimate way to handle such tasks, but my project timeline was very tight, thus I didn't have a time for healthy contribution for this functionality. Looking forward, I think it will be a good thing to provide the markup templating functionality, because it differs for each framework.
I will also think about this and will try to implement something more generic when I will have some more time.
Thanks again.
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?
- Use this with Handlebars? HOT 10
- 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.