logie17 has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need to template this
by dragonchild (Archbishop) on Apr 19, 2007 at 16:15 UTC | |
There are a lot of good reasons to use H::T over TT: Now, TT is more featureful and has its own UI-compatible friends, like Jemplate. It all depends on what your needs are. My criteria for good software: | [reply] |
by Rhandom (Curate) on Apr 19, 2007 at 21:10 UTC | |
TT is too heavy for what you wantSorry - this is long... I hear the "too heavy" argument a lot as a reason to not use TT. I've provided a test script below with benchmarks that show relative speed for a highly contrived template. If TT is used in a mod_perl environment - it is faster than HT. In a non-mod_perl environment (or also in a mod_perl environment you could always use CGI::Ex::Template and then you have the full features of TT with the "lightness" of HTML::Template. The other reason I hear is because they don't want to give too much ability to the HTML designers or because they don't want to have business logic in the templates. The first point seems roughly equivalent to SysAdmins on my network telling me I have to use Lua because they don't want me to have too many features in my programming. On the second point - there is almost nothing you can do to prevent your designers from controlling business logic from the HTML -- Javascript provides all the rope they need to hang themselves. The only option here is to ask them not to do that. So if all the points for using H::T are really veiled non-issues - then the only real reason to pick H::T over TT or likewise to pick TT over H::T is one of religion and is generally based on what system the developer started with in the first place. Well - anyway - the following is a script that tests the templates under different operational modes - passing in a string containing the template, passing in a file containing the template, and caching the template in memory, or the compiled template on the file system (isn't it funny that they all have essentially the same feature sets but have diffent APIs and syntax). This file is included with the CGI::Ex suite under the samples/benchmark directory. Unfortunately the copy of this file on cpan is out of date - but will include this updated file in the next release. Read more... (12 kB)
That script output the output below on my machine (I've removed some of the timethese output to shorten what is presented). Remember that the template is used for the test is trivially short - but it does give a good approximation of "heavy" vs "light". The following abreviations are used:
So using Template Toolkit with the XS stash in a mod_perl environment would offer the best performance (not counting CGI::Ex::Template in a cached environment). I do agree that using TT in a CGI environment without any caching may be a bit heavy (I use CGI::Ex::Template in those cases). This has been a long answer to a short comment about TT being too heavy. Apache is heavy too - but it gets the job done. Personally I use whatever templating system the previous coder used when I go in and maintain code. But on all new work I use CGI::Ex::Template because it gives me the power of TT, but is even faster and lighter.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
| [reply] [d/l] [select] |
by samtregar (Abbot) on Apr 20, 2007 at 16:46 UTC | |
-sam | [reply] |
by Rhandom (Curate) on Apr 21, 2007 at 01:31 UTC | |
by Rhandom (Curate) on Apr 21, 2007 at 04:29 UTC | |
by polettix (Vicar) on Apr 20, 2007 at 13:02 UTC | |
Flavio | [reply] |
|
Re: I need to template this
by stonecolddevin (Parson) on Apr 19, 2007 at 16:13 UTC | |
Well, there really isn't a reason this would start a flame war, T::T is a more powerful library. You have plugins from all sorts of modules, like DBI, CGI, Data::FormValidator, the list goes on. Check out the docs for a more robust list. Out of the two, I'd choose Template::Toolkit. But that's only because I've used both, and found that it provides more of what I need at this point in time. You can do a lot with HTML::Template, it's a really simple and neat little module, but it's hard some times to deal with when you're manipulating large and complex data structures. It would be a good starting point though. Have you looked at HTML::Mason as well? It's a little more like PHP in the sense that you can embed your perl code right into your template, but you can also abstract all your mark up away into "elements" as Mason calls them. Pretty neat if you have mod_perl and some time to install it. Hope this helps!
meh.
| [reply] |
|
Re: I need to template this
by friedo (Prior) on Apr 19, 2007 at 16:19 UTC | |
| [reply] |
|
Re: I need to template this
by rhesa (Vicar) on Apr 19, 2007 at 17:46 UTC | |
| [reply] |
by doom (Deacon) on Apr 20, 2007 at 06:16 UTC | |
Myself, I'm less familiar with Template Toolkit, but I would say if you have a choice of ways to do it, you probably want to use either Mason or Template Toolkit: those are the two competing schools at the moment (notably they both have O'Reilley books), and in effect they're defacto standards.
| [reply] |
|
Re: I need to template this
by derby (Abbot) on Apr 19, 2007 at 16:15 UTC | |
-derby
| [reply] |
|
Re: I need to template this
by talexb (Chancellor) on Apr 19, 2007 at 20:12 UTC | |
I'm going to jump onto the Template::Toolkit bandwagon. The main package for my most recent web application, called File Exchange System, looks like this:
That gives my CGI::Application application session handling, templating, streaming (for stable file downloads) and intelligent database handle handling. In addition to using Template Toolkit for web applications, I also use it for the installation script -- I have configuration file templates (for startup.pl, httpd.conf, Log::Log4perl files, and a main configuration file). I use TT to fill in the blanks to create the actual configuration files, then move the completed files to the appropriate locations. Works great. | [reply] [d/l] |
|
Re: I need to template this
by punch_card_don (Curate) on Apr 19, 2007 at 19:20 UTC | |
In real life, I had a 4-level-deep data structure that TT handled brilliantly with its built-in hash key ability.
Forget that fear of gravity, Get a little savagery in your life. | [reply] |