template toolkit for perl websites, 2
several weeks into the web site project using template toolkit, i can make a few observations that distinguish this web site from one not using template toolkit (specifically the last web site i worked on which was/is a mess).
1) javascript: js includes and function declarations can be put in a "wrapper" template file so that the individual template pages don't have to explicitly include this ugly code. this may be bad for optimization since every page would include js that it is not necessarily using but i am more won-over by clean-looking and maintainable code. with the last web site, each page included often the same js code which a few times had to be modified.
2) database result sets: my approach has been "three-tiered". SQL queries are declared, executed, the result set put into a hash or array of hashes (for multi-record sets) and returned within a function in a "functions" file. the cgi script calls the function, get the returned value which it puts in a var, and passes the variable to the template that it processes. the template uses the variable to display the value(s) or to determine what to present (using the IF/ELSIF/ELSE/END directives). again, these templates are then much more maintainable than web pages that embed the query, its execution, and results.
3) logic in templates: limiting the logic in the templates to the IF/ELSIF/ELSE/END directives and the FOREACH/END directives is working well for this web site and should work well for all our web sites given that they are all of about equal complexity (that is to say, they display SQL results and they accept input to be inserted into DB tables). the only other directives in the templates files are WRAPPER and PROCESS, as of now, which are easily understandable by someone maintaining the presentation layer of the web site.
4) development time: besides the initial 8 hours or so of fumbling around to get a good directory structure set up for the project, i don't think using template toolkit has slowed down development time at all and probably has sped it up.
as more differences/improvements come to me, i will post again but i feel like i could cruise along with what i have learned so far for quite some time.
1) javascript: js includes and function declarations can be put in a "wrapper" template file so that the individual template pages don't have to explicitly include this ugly code. this may be bad for optimization since every page would include js that it is not necessarily using but i am more won-over by clean-looking and maintainable code. with the last web site, each page included often the same js code which a few times had to be modified.
2) database result sets: my approach has been "three-tiered". SQL queries are declared, executed, the result set put into a hash or array of hashes (for multi-record sets) and returned within a function in a "functions" file. the cgi script calls the function, get the returned value which it puts in a var, and passes the variable to the template that it processes. the template uses the variable to display the value(s) or to determine what to present (using the IF/ELSIF/ELSE/END directives). again, these templates are then much more maintainable than web pages that embed the query, its execution, and results.
3) logic in templates: limiting the logic in the templates to the IF/ELSIF/ELSE/END directives and the FOREACH/END directives is working well for this web site and should work well for all our web sites given that they are all of about equal complexity (that is to say, they display SQL results and they accept input to be inserted into DB tables). the only other directives in the templates files are WRAPPER and PROCESS, as of now, which are easily understandable by someone maintaining the presentation layer of the web site.
4) development time: besides the initial 8 hours or so of fumbling around to get a good directory structure set up for the project, i don't think using template toolkit has slowed down development time at all and probably has sped it up.
as more differences/improvements come to me, i will post again but i feel like i could cruise along with what i have learned so far for quite some time.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home