totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

How to show error and success messages in views? #692

Closed Pourya8366 closed 5 years ago

Pourya8366 commented 5 years ago

I want to send flash messages to views in total.js and i see an alternative approach with use of query string and check that flag for know what to show in view:

in controller: this.redirect('/?success=1');

and in related view:

@{if query.success}
    //proper message
@{fi}

but i want to know is there any other approach available to show any status (error or success) messages?

petersirka commented 5 years ago

In some cases I use same approach but I recommend to do it on client-side via JavaScript if it's possible and my next recommendation is to send all forms via AJAX, always. Less code on server-side brings more benefits:


Here is a Flash module with same functionality as in Express.js, but I don't recommend it: https://github.com/totaljs/modules/tree/master/Miscellaneous/flash

For rendering some flash messages you can use controller.repository object or model or you can create some View Engine Helper. There are many ways how to do it.