diff options
-rw-r--r-- | conf/packages | 1 | ||||
-rw-r--r-- | perllib/Page.pm | 64 | ||||
-rw-r--r-- | templates/web/default/header.html | 17 | ||||
-rw-r--r-- | templates/website/header | 19 |
4 files changed, 78 insertions, 23 deletions
diff --git a/conf/packages b/conf/packages index 7828cc699..ecd6c18bc 100644 --- a/conf/packages +++ b/conf/packages @@ -32,3 +32,4 @@ libipc-run3-perl libyaml-perl liblist-moreutils-perl libhaml-ruby +libtemplate-perl diff --git a/perllib/Page.pm b/perllib/Page.pm index 5113f0a40..a7a4349ac 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -25,6 +25,7 @@ use IO::String; use POSIX qw(strftime); use URI::Escape; use Text::Template; +use Template; use Memcached; use Problems; @@ -267,6 +268,67 @@ sub template_include { return $template->fill_in(HASH => \%params); } +=item tt2_template_include + + $html = tt2_template_include( 'header', $q, $vars ); + +Return HTML for a template, given a template name, request, and +any parameters needed. This uses the TT2 templates that the Catalyst port uses. +Intended to prevent having duplicate headers and footers whilst the migration is +in progress. + +=cut + +sub _tt2_template_include_path { + my $q = shift; + + # work out where the emplate dir is relative to the current file + ( my $project_dir = __FILE__ ) =~ s{/[^/]*?$}{}; + my $template_root = "$project_dir/../templates/web"; + + # tidy up the '/foo/..' cruft + 1 while $template_root =~ s{[^/]+/../}{}; + + my @paths = (); + push @paths, "$template_root/$q->{site}" if $q->{site}; # cobrand + push @paths, "$template_root/default"; # fallback + + return \@paths; +} + +sub tt2_template_include { + my ( $template, $q, $params ) = @_; + + # check that the template is 'header.html' or 'footer.html' - this is for + # transition only + unless ( $template eq 'header.html' || $template eq 'footer.html' ) { + warn "template not '(header|footer).html': '$template'"; + return undef; + } + + # create the template object + my $tt2 = Template->new( + { + INCLUDE_PATH => _tt2_template_include_path($q), + ENCODING => 'utf8', + } + ); + + # add/edit bits on the params to suit new templates + $params->{loc} = sub { return _(@_) }; # create the loc function for i18n + $params->{legacy_title} = $params->{title} . $params->{site_title}; + $params->{legacy_rss} = delete $params->{rss}; + + use Data::Dumper; + local $Data::Dumper::Sortkeys = 1; + warn Dumper($params); + + my $html = ''; + $tt2->process( $template, $params, \$html ); + + return $html; +} + =item header Q [PARAM VALUE ...] $html = Page::header( $q, %params ); @@ -319,7 +381,7 @@ sub header ($%) { # produce the html my $vars = template_vars( $q, %params ); - my $html = template_include( 'header', $q, template_root($q), %$vars ); + my $html = tt2_template_include( 'header.html', $q, $vars ); my $cache_val = $default_params{cachecontrol}; if ( mySociety::Config::get('STAGING_SITE') ) { $html .= diff --git a/templates/web/default/header.html b/templates/web/default/header.html index e263aa08d..272e90537 100644 --- a/templates/web/default/header.html +++ b/templates/web/default/header.html @@ -4,10 +4,20 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="/yui/utilities.js"></script> <script type="text/javascript" src="/js.js"></script> + [% map_js %] + [% extra_js_verbatim %] + [% robots %] - [% extra_js_verbatim IF extra_js_verbatim %] - - <title>[% title | html %] :: [% c.cobrand.site_title %]</title> + <title> + [% IF legacy_title %] + [% legacy_title %] + [% ELSE %] + [% title | html %] :: [% c.cobrand.site_title %] + [% END %] + </title> + + + <style type="text/css">@import url("/css/core.css"); @import url("/css/main.css");</style> <!--[if LT IE 7]> <style type="text/css">@import url("/css/ie6.css");</style> @@ -16,6 +26,7 @@ [% IF rss %] <link rel="alternate" type="application/rss+xml" title="[% rss.0 %]" href="[% rss.1 %]"> [% END %] + [% legacy_rss %] </head> <body> diff --git a/templates/website/header b/templates/website/header deleted file mode 100644 index b88d9b82c..000000000 --- a/templates/website/header +++ /dev/null @@ -1,19 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html lang="{{ $lang_code }}"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <script type="text/javascript" src="/yui/utilities.js"></script> - <script type="text/javascript" src="/js.js"></script> - {{ $map_js }} - {{ $robots }} - - <title>{{ $title }}{{ $site_title }}</title> - <style type="text/css">@import url("/css/core.css"); @import url("/css/main.css");</style> - <!--[if LT IE 7]> - <style type="text/css">@import url("/css/ie6.css");</style> - <![endif]--> - {{ $rss }} - </head> - <body> - {{ $heading_element_start }}{{ $heading }}{{ $heading_element_end }} - <div id="wrapper"><div id="mysociety"> |