From 8dc155f122b7c8276cd6a472a1ac43709d3b8962 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 4 Jan 2021 10:29:11 -0500 Subject: [PATCH] Bug 27334: Add Template Toolkit support to news items It would be useful if news items could take advantage of template toolkit syntax. Test Plan: 1) Apply this patch 2) Edit a news item 3) Add some TT to the content like "[% IF 1 %]It works![% END %]" 4) View the rendered news item on mainpage.pl 5) Note the TT is rendered correctly! Signed-off-by: Sally Signed-off-by: Katrin Fischer --- C4/NewsChannels.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index 7c9df5b2e5..83f768e6a9 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -19,9 +19,12 @@ package C4::NewsChannels; # along with Koha; if not, see . use Modern::Perl; + use C4::Context; use Koha::DateUtils; +use Carp qw(croak); + use vars qw(@ISA @EXPORT); BEGIN { @@ -211,9 +214,29 @@ sub GetNewsToDisplay { my $sth = $dbh->prepare($query); $lang = $lang // q{}; $sth->execute($lang,$branch); + + my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; + my $template = Template->new( + { + EVAL_PERL => 1, + ABSOLUTE => 1, + PLUGIN_BASE => 'Koha::Template::Plugin', + COMPILE_EXT => $use_template_cache ? '.ttc' : '', + COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', + FILTERS => {}, + ENCODING => 'UTF-8', + } + ) or die Template->error(); + my @results; while ( my $row = $sth->fetchrow_hashref ){ $row->{newdate} = output_pref({ dt => dt_from_string( $row->{newdate} ), dateonly => 1 }); + + my $content = $row->{content}; + my $output; + $template->process( \$content, {}, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); + $row->{content} = $output; + push @results, $row; } return \@results; -- 2.11.0