Quoting Steven Bauer <[EMAIL PROTECTED]>:
> I am working on a project using CGI::Application.
>
> CGI::Application seems to default to using HTML::Template by
> default, which I tried to override by requiring HTML::Template:Expr
> in my application.
>
> However, when I use expression sytax, I get syntax errors from
> my template, because Expr is not being used when the template is
> being loaded.
>
> How do I ensure that HTML::Template::Expr is used with CGI::Application.
This should probably be asked on the CGI::Application mailing list, but I'll
answer it anyway.
The load_tmpl function in CGI::Application is really just a helper function, and
doesn't need to be used in order to use HTML::Template. Just create the
template object yourself in your run modes.
my $template = HTML::Template::Expr->new(...);
If you really want to use the load_tmpl function in your code, then override it
with your own version.
sub load_tmpl {
my $self = shift;
my ($tmpl_file, @extra_params) = @_;
# add tmpl_path to path array of one is set, otherwise add a path arg
if (my $tmpl_path = $self->tmpl_path) {
my $found = 0;
for( my $x = 0; $x < @extra_params; $x += 2 ) {
if ($extra_params[$x] eq 'path' and
ref $extra_params[$x+1] and
ref $extra_params[$x+1] eq 'ARRAY') {
unshift @{$extra_params[$x+1]}, $tmpl_path;
$found = 1;
last;
}
}
push(@extra_params, path => [ $tmpl_path ]) unless $found;
}
require HTML::Template::Expr;
my $t = HTML::Template::Expr->new_file($tmpl_file, @extra_params);
return $t;
}
All I have done here is taken the exact load_tmpl function from
CGI::Application, and changed the HTML::Template calls to HTML::Template::Expr.
Put this in your superclass and all your template objects will be Expr objects.
You will have a performance hit on your templates that don't require H::T::E, so
I would recommend you use the first method. Or perhaps even better, create a
load_tmpl_expr function that uses HTML::Template::Expr and leave load_tmpl as
is. That would give you the option to choose the right one in your run mode.
That might not be a bad addition to the CGI::Application core...
Cheers,
Cees
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users