node.jstotal.js

Show error and success messages in views total.js?


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?


Solution

  • 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.