(09-24-2015, 06:57 AM)spjonez Wrote: While a neat concept, views should not contain logic or be calling functions.
While this is an ideal which one should look to attain in their views, at some point someone has to look around and realize that some views must do one or the other, or you have to back-door the situation by using a template language which allows you to specify logic (and sometimes function calls) without technically including it directly in the view.
In fact, this ultimate goal is one of the reasons I cited for using this functionality in the first place, as I was faced with one of three other methods of handling this particular task:
- Looping through my data in the controller to modify it for display before passing it to the view, where the view would loop through the data again to generate the HTML in which it is displayed.
- Putting all of the logic contained in these closures into the view itself to avoid the second loop.
- Putting the logic into helper functions or library methods which would be called from the view.
How exactly does one accomplish even a simple list without logic or function calls in their view? At some point you're going to need at least a loop.