News, Events, Trends, Activities, Conferences and Notes to do with Web Culture, Development, New Media, Content Management, Mobile and PDA Access and Web Infrastructure
|
See Also: Home Links Personal Site Blogroll FriendFeed CV | |
Wiki Menu:Tags:
|
Template ToolkitThis presentation was by Perl maestro Randall Schwartz (RS) at OSDC 2006. He rattled thru the talk pretty quick, but it was infomative, entertaining, and pretty much confirmed what I'd heard that this is a powerful and good performing templating system. RS says he uses it in all his web apps and for publishing stuff on his personal website. Its also the templating engine behind sites like Slashdot (aka Slash Code ) so it certainly scales ok. The toolkit has been at its current version2 for a good few years and the promise of version 3 is joked about apparently on the list, folks are betting whether Perl-6 or Template::Toolkit (TT) ver3 will be released 1st There is one main lead developer ( Andy Wardley ) and a bunch of contributors, with a ver active user community, and useful mailing list. Altho its fairly fully featured you can also embed Perl inline but RS made the point that if youre struggling to make the TT language do what you want to you should probably be using external perl or a plugin. As RS pointed out there are loads of templating systems out there, but he favours this, and reckons it really does offer good seperation of code, and front-end templating language (which seems like it would be relatively easy for a non-coder to pickup) Theres no point in me replicating Usage Examples etc here, but in summary TT has a templaing language you embed in a file which you then parse with the a new instance of a Template::Tookit object in Perl. The language has control flow directives, supports runtime variables (scalars, hashes, arrays), you can pass this data into the template and echo it out or iterate over it. You can include templates within others, and extend it by building your own plugin filter module. These filter and plugin features are killer, theres out-of-the-box support for handling things like XML, RSS, gd-library etc, and apparently a bunch of other filters on cpan. Theres some nice iterator like features which are kinda Java-ish (and appently Perl-6-ish) which would make building tables of text or lists for example in html a piece of cake. When the template is parsed it is compiled into Perl code and the compiled template saved out to disk so it can be reloaded from there for future requests without recompiling. TT is obviously used to dynamically spit out content (in Slashdots case) but there is also a lot of use of it for burning static copies of content out to a file system location, from where a web server could serve it as plain static html. There are a couple of command-line tools to handle this rendering. RS pointed out a few weird less often used "features" of TT which he says are kinda legacy, and generally a result of Andy making a change to the code following some incoming user request, there are some behaviours that you need to be aware of (eg not using '_' in has element keynames) but I guess theres a gotcha/faq somewhere covering these. I actually asked SAD to install TT on Asterix some time back, I had a quick play with it at the time, but not sure if its still on the machine. This is definately something that would be useful a web team armoury.
See Also: OSDC 2006 | Perl | Web Development | Notes Index |