View Helpers
flashMessages()
Signature
Section titled “Signature”flashMessages() — returns string
Available in: controller
Category: Miscellaneous Functions
Description
Section titled “Description”Displays a marked-up listing of messages that exist in the Flash.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
keys | string | no | — | The key (or list of keys) to show the value for. You can also use the key argument instead for better readability when accessing a single key. |
class | string | no | flash-messages | HTML class to set on the div element that contains the messages. |
includeEmptyContainer | boolean | no | false | Includes the div container even if the Flash is empty. |
encode | boolean | no | true | Use this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content. |
Examples
Section titled “Examples”// 1. Display all Flash messages in a view
// In the controller action:
flashInsert(success="Your post was successfully submitted.");
flashInsert(alert="Don't forget to tweet about this post!");
flashInsert(error="This is an error message.");
// In the layout or view:
writeOutput(flashMessages());
// Generates (keys sorted alphabetically):
// <div class="flash-messages">
// <p class="alert-message">Don't forget to tweet about this post!</p>
// <p class="error-message">This is an error message.</p>
// <p class="success-message">Your post was successfully submitted.</p>
// </div>
// 2. Show only a single Flash key using the `key` alias
writeOutput(flashMessages(key="success"));
// Generates:
// <div class="flash-messages">
// <p class="success-message">Your post was successfully submitted.</p>
// </div>
// 3. Show a specific set of keys in a defined order using `keys`
writeOutput(flashMessages(keys="success,alert"));
// Generates (in the order supplied, not alphabetically):
// <div class="flash-messages">
// <p class="success-message">Your post was successfully submitted.</p>
// <p class="alert-message">Don't forget to tweet about this post!</p>
// </div>
// 4. Always render the container div, even when the Flash is empty
writeOutput(flashMessages(includeEmptyContainer=true));
// Generates:
// <div class="flash-messages"></div>
// 5. Use a custom CSS class on the outer container
writeOutput(flashMessages(class="notifications"));
// Generates:
// <div class="notifications">
// <p class="alert-message">Don't forget to tweet about this post!</p>
// <p class="error-message">This is an error message.</p>
// <p class="success-message">Your post was successfully submitted.</p>
// </div>