This is a Web2py plugin for manage messages in the views using the toast library. To install the plugin it is necessary to use the web2py plugin manager.
- Use Boostrap 4 library in the layout
- Include web2py_ajax.html file in the layout
plugin_toastr_message_config('type_message', 'message_text', ajax=False)
-
type_message(string): Define the message css style. Can be:
-
success: Show a success message
-
error: Show an error message
-
-
message_text(string): Define the message text.
-
ajax(bool): Used when working with web2py ajax components. Allows the message to be displayed asynchronously:
- Important: In case of using the messages in an asynchronous controller and using the response.js variable, it is necessary to call the plugin_toastr_message_config() method after the last use of the response.js variable.
After installing the plugin in the web2py plugin manager it is necessary to add a few lines of code in the main layout.
- Add the next code to view/layout.html (the main layout) into the body tag (preferably last):
{{=plugin_toastr_message()}}
<div id="plugin-toastr-message"></div>
- To launch the message, include the next code in a controller.
plugin_toastr_message_config('success', 'All good', ajax=False)
Or
plugin_toastr_message_config('error', 'Oops!! An error has occurred!', ajax=False)
Many thanks to Ronald William Pérez Sánchez for his help.