From c0f198fa60b783b3fcdabf6e8a2e121bb2794662 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 30 Dec 2010 16:25:39 +0100 Subject: [PATCH] Hilfsfunktion 'render()' zum Rendern von Templates inklusive Titel & $::form->header zzgl. notwendiger Anpassung von locales.pl --- SL/Controller/Base.pm | 24 ++++++++++++++++++++++++ scripts/locales.pl | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/SL/Controller/Base.pm b/SL/Controller/Base.pm index a2a380b93..4f6bd196e 100644 --- a/SL/Controller/Base.pm +++ b/SL/Controller/Base.pm @@ -37,6 +37,21 @@ sub redirect_to { print $::cgi->redirect($url); } +sub render { + my $self = shift; + + my $template; + $template = shift if scalar(@_) % 2; + my %params = @_; + + if ($params{title}) { + $::form->{title} = delete $params{title}; + $::form->header; + } + + print $self->parse_html_template($template, $params{locals}); +} + # # private functions -- for use in Base only # @@ -157,6 +172,15 @@ Outputs an HTML template. It is a thin wrapper around C which also adds the current object as the template variable C. +=item C + +Renders the template C<$template> by calling +L. C<$params{locals}> will be used as the second +parameter to L. + +If C<$params{title}> is trueish then the function also sets +C<< $::form->{header} >> to that value and calls C<< $::form->header >>. + =item C =item C diff --git a/scripts/locales.pl b/scripts/locales.pl index a5ec52fdc..bdc3852af 100755 --- a/scripts/locales.pl +++ b/scripts/locales.pl @@ -346,7 +346,7 @@ sub scanfile { } # is this a template call? - if (/parse_html_template2?\s*\(\s*[\"\']([\w\/]+)\s*[\"\']/) { + if (/(?:parse_html_template2?|render)\s*\(\s*[\"\']([\w\/]+)\s*[\"\']/) { my $newfile = "$basedir/templates/webpages/$1.html"; if (/parse_html_template2/) { print "E: " . strip_base($file) . " is still using 'parse_html_template2' for " . strip_base($newfile) . ".\n"; -- 2.20.1