Bugzilla – Attachment 115309 Details for
Bug 27334
Add Template Toolkit support to news items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27334: Add Template Toolkit support to news items
Bug-27334-Add-Template-Toolkit-support-to-news-ite.patch (text/plain), 2.10 KB, created by
Kyle M Hall (khall)
on 2021-01-19 11:43:11 UTC
(
hide
)
Description:
Bug 27334: Add Template Toolkit support to news items
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2021-01-19 11:43:11 UTC
Size:
2.10 KB
patch
obsolete
>From bb05b6fca2f6bdc1a06e97751a33ac2cfc03b092 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >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! >--- > 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 <http://www.gnu.org/licenses>. > > 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.24.1 (Apple Git-126)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27334
:
114808
|
115309
|
115310
|
116159
|
116467
|
116468