Pourya8366
Pourya8366

Reputation: 3684

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?

Upvotes: -1

Views: 76

Answers (1)

Peter Sirka
Peter Sirka

Reputation: 748

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:

  • less CPU and memory consuption on server-side
  • output of view can be cached
  • better performance
  • smaller transmission data

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.

Upvotes: 1

Related Questions