|Think about Loose Coupling|
Re: Re: RFC: Template::YetAnotherby domm (Chaplain)
|on Nov 16, 2002 at 15:57 UTC||Need Help??|
the benefit of templates is not separating code from the presentation. It's decoupling the application logic and the presentation logic.
My problem with presentation logic vs application logic is where to draw the line.
In your example, I would consider the warning about no people to be found to be part of the application logic. The template should just display this warning.
In my proposed system, your example probably would look like this:
By pushing the presentation logic back into the application, then the application needs to know how the data is to be presented. If later you need to change the presentation of the data, you're forced to change the application!
The application doesn't need to know how the data is to be presented. It only needs to know what sort of data it is handling. The data then gets tagged (mis)using Perl's OO fetures (attributes would be another solution, I guess). The Templating System looks at those tags that describe data, chooses the appropriate template and fills in the data.
One reason for starting to to think about my proposal was the problem of testing web applications. I asked Schwern about that on YAPC::EU 2002 and he said (more or less) one simple way to test Web Apps is to test the data each function/method returns before it gets passed to the template (So you do not have to parse the HTML in the test...)
Until now I use a simple homegrown regex as a "templating system". It sucks. But none of the multitude of Templating Systems an CPAN really convinced me.
But maybe I should take a much closer look at TT (which seems to be one of the better Templating Systems). I used TT a little bit when working on the mod_perl site and it definitly wasn't love at the first sight...
Thanks for the feedback, anyway!