more useful options | |
PerlMonks |
Re: Re: I am about to write my very own templating module..by ajt (Prior) |
on Sep 26, 2001 at 13:33 UTC ( [id://114766]=note: print w/replies, xml ) | Need Help?? |
I have a great deal of sympathy with Screemer on this one. Both Perrin and Mirod have valid points, but conceptually there are problems with all the current templating methods.
I use to work for a company that helped to invent DOM and XML. We built quite a clever HTML/XML templating engine built around XPath/XPointer and DOM. Problem was the code was spagetti, and we built much of it before we submitted proposals to the W3C, so it was a bit pre-standards. The key thing about the templating method, and the thing I still like about it most, was that the source and template were both XML. Basically the engine traversed the template XML DOM tree, and when it found an instruction, it pulled content via XPath from the content document, or via another script. The beauty of this approach is that the template and source are well-formed XML/HTML that can be worked on with any respectable HTML/XML tool. The templating engine just did templating and not much else, and "smarts" are independent from both the templating engine and the souce/template files. I am not able to use this tool in my current role as it was built in a proprietary BASIC like language, in a server plug-in to servers other than Apache. I know I'm a heretic for doing this, but I built my own templating engine in Perl, using CGI and Perl. It's 600 lines of Perl, including comments and POD. It works real well. It uses as many modules as I could find to keep the bits I wrote as short and simple as possible. At the moment I'm trying to tease it to work on mod_Perl, where it will be fast enough to use in a small multi-user environment. I contacted various people, and got good feedback from several template authors, but their templating methods just were not what I was looing for, though TT2 came closest. Here is how it works.......
The engine understands requests to get files via HTTP, FTP, or from the local file system. When it has got a file, it can use HTTP::TreeBuilder, XML::TreeBuilder or XML::XPath to extract a given fragment. So if you want to call a dynamic menu for example, you simply place a call in the template to a script (any language) that makes a dynamic navigation fragment, then you parse or grab verbaitim the bit you want. At the moment I pass all pages through HTML-Tidy to clean them up, but this is easy to configure if you want to change it. To publish the finished pages, I simply use GNU WGet to suck all the pages of the server, and then FTP them to a production server for final delivery. This solution is not fast, it's not supposed to be, but it's faster than I thought, and is getting faster. I probably could implement it in TT2, but as mod_Perl is flakey on NT/Apache yet (Re: Re: Re: (jeffa) Re: Good place to learn Apache::PerlRun), this isn't an option for me. I built a little ego site using this technology, and it performed perfectly. The site is a bit lame, so apologies to monks who look at it... I know I have gone against the advice of more learned monks... but sometimes you have to try something to learn, even if it turns out to be a mistake!
In Section
Seekers of Perl Wisdom
|
|