Better template diagnostics on failure. It now also includes the template URL, and templateId
in both the onscreen and logged output.
This commit is contained in:
parent
4252b359dc
commit
8a683d1aef
9 changed files with 100 additions and 73 deletions
|
|
@ -16,6 +16,7 @@ package WebGUI::Asset::Template::HTMLTemplate;
|
|||
|
||||
use strict;
|
||||
use base 'WebGUI::Asset::Template::Parser';
|
||||
use WebGUI::Exception;
|
||||
use HTML::Template;
|
||||
|
||||
|
||||
|
|
@ -37,7 +38,7 @@ sub getName {
|
|||
|
||||
=head2 process ( template, vars )
|
||||
|
||||
Evaluate a template replacing template commands for HTML.
|
||||
Evaluate a template replacing template commands for HTML.
|
||||
|
||||
=head3 template
|
||||
|
||||
|
|
@ -50,28 +51,25 @@ A hash reference containing template variables and loops.
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my $template = shift;
|
||||
my $vars = $self->addSessionVars(shift);
|
||||
my $t;
|
||||
eval {
|
||||
$t = HTML::Template->new(
|
||||
scalarref=>\$template,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
strict=>0
|
||||
);
|
||||
};
|
||||
unless ($@) {
|
||||
$t->param(%{$vars});
|
||||
return $t->output;
|
||||
} else {
|
||||
$self->session->errorHandler->error("Error in template. ".$@);
|
||||
return WebGUI::International->new($self->session, 'Asset_Template')->get('template error').$@;
|
||||
}
|
||||
my $self = shift;
|
||||
my $template = shift;
|
||||
my $vars = $self->addSessionVars(shift);
|
||||
my $t;
|
||||
eval {
|
||||
$t = HTML::Template->new(
|
||||
scalarref=>\$template,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
strict=>0
|
||||
);
|
||||
};
|
||||
if ($@) {
|
||||
WebGUI::Error::Template->throw( error => $@ );
|
||||
}
|
||||
$t->param(%{$vars});
|
||||
return $t->output;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package WebGUI::Asset::Template::HTMLTemplateExpr;
|
|||
use strict;
|
||||
use base 'WebGUI::Asset::Template::Parser';
|
||||
use HTML::Template::Expr;
|
||||
use WebGUI::Exception;
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -77,25 +78,23 @@ A hash reference containing template variables and loops.
|
|||
# about the template that has the error. Finding an "ERROR: Error in template"
|
||||
# in the error log is not very helpful...
|
||||
sub process {
|
||||
my $class = shift;
|
||||
my $template = shift;
|
||||
my $vars = $class->addSessionVars(shift);
|
||||
my $t;
|
||||
eval {
|
||||
$t = HTML::Template::Expr->new(scalarref=>\$template,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
strict=>0);
|
||||
};
|
||||
unless ($@) {
|
||||
$t->param(%{_rewriteVars($vars)});
|
||||
return $t->output;
|
||||
} else {
|
||||
$class->session->errorHandler->error("Error in template. ".$@);
|
||||
return WebGUI::International->new($class->session,'Asset_Template')->get('template error').$@;
|
||||
}
|
||||
my $class = shift;
|
||||
my $template = shift;
|
||||
my $vars = $class->addSessionVars(shift);
|
||||
my $t;
|
||||
eval {
|
||||
$t = HTML::Template::Expr->new(scalarref=>\$template,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
strict=>0);
|
||||
};
|
||||
if ($@) {
|
||||
WebGUI::Error::Template->throw( error => $@ );
|
||||
}
|
||||
$t->param(%{_rewriteVars($vars)});
|
||||
return $t->output;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -71,25 +71,22 @@ A hash reference containing template variables and loops.
|
|||
# about the template that has the error. Finding an "ERROR: Error in template"
|
||||
# in the error log is not very helpful...
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my $template = shift;
|
||||
my $vars = $self->addSessionVars(shift);
|
||||
my ($t,$output);
|
||||
eval {
|
||||
$t = Template->new( {
|
||||
INTERPOLATE => 1, # expand "$var" in plain text
|
||||
POST_CHOMP => 1, # cleanup whitespace
|
||||
EVAL_PERL => 0, # evaluate Perl code blocks
|
||||
});
|
||||
$t->process( \$template, _rewriteVars($vars),\$output) || $self->session->errorHandler->error($t->error());
|
||||
};
|
||||
unless($@){
|
||||
return $output;
|
||||
} else {
|
||||
$self->session->errorHandler->error("Error in template. ".$@);
|
||||
return WebGUI::International->new($self->session,'Asset_Template')->get('template error').$@;
|
||||
}
|
||||
|
||||
my $self = shift;
|
||||
my $template = shift;
|
||||
my $vars = $self->addSessionVars(shift);
|
||||
my ($t,$output);
|
||||
eval {
|
||||
$t = Template->new({
|
||||
INTERPOLATE => 1, # expand "$var" in plain text
|
||||
POST_CHOMP => 1, # cleanup whitespace
|
||||
EVAL_PERL => 0, # evaluate Perl code blocks
|
||||
});
|
||||
$t->process( \$template, _rewriteVars($vars),\$output) || $self->session->errorHandler->error($t->error());
|
||||
};
|
||||
if ($@) {
|
||||
WebGUI::Error::Template->throw( error => $@ );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package WebGUI::Asset::Template::SomeTemplateType;
|
|||
|
||||
use strict;
|
||||
use base 'WebGUI::Asset::Template::Parser';
|
||||
use WebGUI::Exception;
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -52,7 +53,12 @@ sub process {
|
|||
my $self = shift;
|
||||
my $template = shift;
|
||||
my $vars = $self->addSessionVars(shift);
|
||||
...
|
||||
eval {
|
||||
|
||||
}
|
||||
if ($@) {
|
||||
WebGUI::Error::Template->throw( error => $@ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue