sails-hook-flash
The simplest way to use flash messages in your Sails application. This is useful when you want to redirect and have a special message shown on the next page.
Installation
npm install sails-hook-flash
Use --save
to add in your package.json.
Example
Adding a new flash message:
// api/controllers/SampleController.js { request; return response;}
Rendering your flash message:
// views/sample/success.ejs<% flash %>
NOTE: The EJS view engine is used in this sample, but you're not limited to it.
Usage
Controller layer
request.addFlash(type, message)
- Stores a new messagerequest.getFlash(type)
- Returns all messages from a typerequest.hasFlash(type)
- Checks if a message type was stored
View layer
flash.all()
- Returns all messagesflash.get(type)
- Returns all messages from a typeflash.has(type)
- Checks if a message type was stored