FlashMessenger
A simple and lightweight flash-message module for Express and Twitter Bootstrap.
Features
- You can create Twitter Bootstrap alerts from server
- Icon support
- Multi-Alert support
- Multi-Message support in one alert
- Supports multiple redirects
- Auto-rendering: No need to create a template var for a partial or block
- FlashMessenger can be accessed from response object
Install
npm install flash-messenger --save
Initialization
var FlashMessenger = ; app;
Setup !IMPORTANT
After installation you need to create a template partial file. For handlebars template engine you can use the code below. If you want to write your own style make sure you are using the correct template vars. The most important is:
flashMessengeralertsBeforeFlush
This will return the stored alerts. The alerts stored in the session will be deleted.
Template
The following exampe is written in Handlebars. Simply copy the code, create a partial and call it in your layout.hbs file. If you are using another template engine you need to translate the code into the syntax of your template engine.
{{#each flashMessenger.alertsBeforeFlush}} {{#if this.canBeDismissed}} × {{/if}} {{#if this.titleIcon}} {{/if}} {{this.title}} {{#if this.messages}} {{#each this.messages}} {{this}} {{/each}} {{/if}} {{/each}}
Usage
After initialization the property flashMessenger is accessable from the respone object:
app //This creates an Bootstrap error alert resflashMessenger; res; //that's it. The rendering works automatically
Note: Typically flash message module only supports redirects. In this one you do not need to make a redirect to use it. You can simply render it directly. Redirects are also supported.
More Actions
app //This creates an Bootstrap success alert with the title: 'Yeah, you did it.' var alert = resflashMessenger; //Make the alert box dismissable alertisDismissible = true; //set an font awesome icon alerttitleIcon: 'fa fa-thumbs-o-up' alert; alert; alert; //This creates another Bootstrap alert with the type info and the title: 'Here comes another info' var anotherAlert = resflashMessenger; resflashMessenger; res; //that's it. The rendering of the bootstrap alerts works automatically
Template Vars
The following template vars can be used to customize the view if neccessary.
1 array flashMessenger2 string alerttype danger error info success3 bool alertcanBedismissed 4 string alert5 array alert