I'm writing a javascript web app using Backbone and Marionette, and my templates are created using Handlebars.
I have a view with three sections: a progress indicator, results list, and footer. Each of these may be shown or hidden based on if an operation is in progress or if there was an error.
Should I include conditional code in the Handlebars template, along the lines of {{unless resultsFetched}}
and do this.render()
often, or use javascript in the view like this.ui.resultsList.show()
and this.ui.resultsList.hide()
?
Thanks.
Update
Here are what I think are some pros and cons to having logic in the view templates:
Pros:
- I think this looks like a declarative (instead of imperative) style, where the view says that it'll act a certain way based on model state.
- As things get more complex, it'd probably be easier to read a template that has conditional logic than javascript code where
show()
andhide()
is used extensively.
Cons:
- Is the MVC architecture still being obeyed?
- This goes against Mustache's philosophy of logic-less views