Comments (2)
I think it always returns array.
from connect-flash.
Same here. If in your route or render method you set messages variable like
messages: req.flash()
Then you will get a messages variable in the rendered view which will be eqal to
{[]}
because req.flash() will still create an empty array.
So yes in your view you will need to check the length is not 0
I made a partial for flash messages that checks for both the existence and the length so I can include it at the top of all views
<% if(typeof messages !== 'undefined') { %>
<% if (typeof messages.error !== 'undefined' && messages.error.length > 0) { %>
<p class="error"><%= messages.error %></p>
<% } %>
<% if (typeof messages.info !== 'undefined' && messages.info.length > 0) { %>
<p class="info"><%= messages.info %></p>
<% } %>
<% if (typeof messages.success !== 'undefined' && messages.success.length > 0) { %>
<p class="info"><%= messages.success %></p>
<% } %>
<% } %>
For ejs templates at top of body
<% include partials/flash.server.partial.html %>
This way I can just use req.flash() in my render function and every view will check for the existence of the 3 types of error messages I might or might not have flashed at some point in the process.
from connect-flash.
Related Issues (20)
- Using app.configure in example code HOT 1
- flash for node 0.12 and lower version
- Passing an object value to req.flash() HOT 5
- about the name HOT 1
- Req.flash() automatic set session when it's not required to do so. HOT 5
- Use flash scope in Handlebars template without passing the value through controllers
- app.configure is not a function HOT 3
- radical reusability link in readme broken HOT 1
- req.flash return content with brackets ['message'] HOT 7
- Connect Flash is not working in Express 4.16.3 HOT 4
- req.flash() returning different values on same scope HOT 1
- req.flash returns empty array HOT 3
- Error: req.flash() requires sessions HOT 2
- util.isArray(object) is deprecated
- What is the `unsafe` option?
- Node.js req.flash issues
- is this still being maintained? HOT 2
- dsfsdfsd
- express JS - connect-flash doesnt work fine when i use express-mysql-session
- Deprecation Warning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead. 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 connect-flash.