On 9/16/05, suppressed <suppressed> wrote:
> Michael gave a great example of how to use TT to wrap a template with a
> "layout".
>
> I'm starting to explore TT today and have a couple questions on using it
> with C:A.
>
> 1) Is there a good C:A + TT tutorial or cookbook example?
Not that I know of, but it would be a welcome addition. However,
there is really nothing special about using TT with C::A. The TT
integration is very light, and is more done for convenience that
necesity. Anything you read on the Template Toolkit docs or tutorials
should apply to using it in CGI::Application.
> I looked at the TT tutorials, but I didn't find a C:A integration
> example. Michael's example of loading the TT template is simple (I
> probably just need to include the pkg, and use the code he gave
> below)... but I'm paranoid and perhaps it really isn't that easy and
> there are other things to consider. :-)
If you are using the ::TT plugin, then things will work very similar
to using Template Toolkit directly. At it's simplest level (and most
don't need to use anything beyond this), you will just need to use the
tt_config method to provide any custom configuration options to
Template Toolkit, and after that, you just call tt_process when you
want to process a template.
Here is an example of how to configure Template Toolkit using the TT
plugin, and in this case we are setting a default wrapper template to
be used on all templates.
our $TEMPLATE_OPTIONS = {
COMPILE_DIR => '/tmp/tt_cache',
INCLUDE_PATH => '/path/to/template/files',
WRAPPER => 'wrapper.tmpl',
};
__PACKAGE__->tt_config( TEMPLATE_OPTIONS => $TEMPLATE_OPTIONS );
Now any runmodes that use the tt_process method will automatically be
wrapped by the wrapper.tmpl template.
sub myrunmode {
my $self = shift;
my %params = {
menu => [
{ title => 'Home', href => '/home.html',
title => 'Download', href =>
'/download.html', },
],
};
return $self->tt_process('myrunmode.tmpl', \%params);
}
> 2) Should I use Any::Template ... or just go C:A + TT?
That is really a personal decision. If you think you may be using
different templating systems in your application, then it makes sense
to use the AnyTemplate module. However, if you are just using
Template Toolkit, then it may not give you much benefit over the TT
plugin.
> 2a) If I do, how do I pass in the "WRAPPER" param?
See the example above for TT. As for AnyTemplate, I know it is
possible, I just don't know how since I haven't used it (check the
docs, or wait for Michael to respond ;).
> 3) C:A seems more active than ever! (especially all the cool new
> plugins!) -- and with the Magic Dot pkg, HT also seems relatively active
> whereas TT is has been at "3.x coming soon" for a long while. Is there
> any chance that similar "WRAPPER" and "SET" functionality might be
> easily hacked into HT?
Wrapper can be emulated using a custom filter, And SET is provided by
one of the many HTML::Template subclasses floating around. I would
stay away from those until they are rewritten to take advantage of the
new plugin system that was just released. That will make using these
extensions safer and cleaner.
However, you should look at your reasons for sticking with
HTML::Template. I don't think that the speed of HTML::Template is
that different from TT (ignoring HTML::Template::Jit of course). So
you should base the decision on the features you need (not necesarily
on the features that are available!). Do you want lots of features
and flexibility that will allow you to do pretty much anything you
need (including turning your templates into horrible monstrosities
with embeded SQL and embedded perl if you unwisely choose to do so).
Or do you have no self control to keep the templates clean and so
should use a system like HTML::Template that forces its simplicity on
you without recourse.
Of course my opinion is biased since I use TT almost exclusively now,
but I fully understand (and support) the reasons why people use
HTML::Template.
Cheers,
Cees
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.