Back
flashMessages()
The flashMessages() function generates a formatted HTML output of messages stored in the Flash scope. It is typically used in views or layouts to display temporary notifications like success messages, alerts, or errors. You can choose to display all messages, a specific key, or multiple keys in a defined order. Additional options let you customize the container’s HTML class, include an empty container if no messages exist, and control whether the message content is URL-encoded.
// 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 --->
#flashMessages()#
<!--- Generates this (sorted alphabetically):--->
<div class="flashMessages">
<p class="alertMessage">
Don't forget to tweet about this post!
</p>
<p class="errorMessage">
This is an error message.
</p>
<p class="successMessage">
Your post was successfully submitted.
</p>
</div>
<!--- Only show the "success" key in the view --->
#flashMessages(key="success")#
<!--- Generates this: --->
<div class="flashMessage">
<p class="successMessage">
Your post was successfully submitted.
</p>
</div>
<!--- Show only the "success" and "alert" keys in the view, in that order --->
#flashMessages(keys="success,alert")#
<!--- Generates this (sorted alphabetically):--->
<div class="flashMessages">
<p class="successMessage">
Your post was successfully submitted.
</p>
<p class="alertMessage">
Don't forget to tweet about this post!
</p>
</div>
Copied!