Skip to content

robjr/sails-hook-flash

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sails-hook-flash

NPM Version NPM Download Travis CI Coverage Status

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
login: function (request, response) {
  request.addFlash('success', 'A success message.');
  return response.redirect('/sample/success');
}

Rendering your flash message:

// views/sample/success.ejs
<% flash.get('success').forEach(function (message) { %>
    <div style="color:green;">
      <%= message %>
    </div>
<% }) %>

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 message
  • request.getFlash(type) - Returns all messages from a type
  • request.hasFlash(type) - Checks if a message type was stored

View layer

  • flash.all() - Returns all messages
  • flash.get(type) - Returns all messages from a type
  • flash.has(type) - Checks if a message type was stored

About

Flash message for Sails applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%