Bugzilla – Attachment 150511 Details for
Bug 33030
Add standardized subroutine for processing Template Toolkit syntax outside of notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33030: Add standardized subroutine for processing Template Toolkit syntax outside of notices
Bug-33030-Add-standardized-subroutine-for-processi.patch (text/plain), 3.96 KB, created by
David Nind
on 2023-05-02 11:06:07 UTC
(
hide
)
Description:
Bug 33030: Add standardized subroutine for processing Template Toolkit syntax outside of notices
Filename:
MIME Type:
Creator:
David Nind
Created:
2023-05-02 11:06:07 UTC
Size:
3.96 KB
patch
obsolete
>From 3372a0c1cd86869d50e5034bfdd8e86ae2edb67e Mon Sep 17 00:00:00 2001 >From: Kyle Hall <kyle@bywatersolutions.com> >Date: Tue, 21 Feb 2023 14:17:09 -0500 >Subject: [PATCH] Bug 33030: Add standardized subroutine for processing > Template Toolkit syntax outside of notices > >Koha has evolved to use Template Toolkit for many uses outside of generating slips and notices for patrons. Historically, each of these areas processed template toolkit in a slightly different way. We should add a module to allow Template Toolkit syntax to be processed in a standard and generic way such that all non-notice TT syntax is handled and processed the consistently. > >Test Plan: >1) Apply this patch >2) prove t/db_dependent/Koha/Items.t > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/TemplateUtils.pm | 100 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 100 insertions(+) > create mode 100644 Koha/TemplateUtils.pm > >diff --git a/Koha/TemplateUtils.pm b/Koha/TemplateUtils.pm >new file mode 100644 >index 0000000000..1ecdea7d5a >--- /dev/null >+++ b/Koha/TemplateUtils.pm >@@ -0,0 +1,100 @@ >+package Koha::TemplateUtils; >+ >+# Copyright ByWater Solutions 2023 >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Carp qw( croak ); >+use Try::Tiny; >+use Template; >+ >+use C4::Context; >+ >+use vars qw(@ISA @EXPORT_OK); >+ >+BEGIN { >+ require Exporter; >+ @ISA = qw(Exporter); >+ @EXPORT_OK = qw( process_tt ); >+} >+ >+=head1 NAME >+ >+Koha::TemplateUtils >+ >+A module to centralize and standardize processing of template toolkit syntax >+for uses other than slips and notices. >+ >+=head1 DESCRIPTION >+ >+Koha has evolved to use Template Toolkit for many uses outside of generating slips and notices for patrons. Historically, each of these areas processed template toolkit in a slightly different way. This module is meant to allow Template Toolkit syntax to be processed in a standard and generic way such that all non-notice TT syntax is handled and processed the consistently. >+ >+=head2 process_tt >+ >+$processed = process_tt($template, $vars); >+ >+Process the given Template Toolkit string, passing the given hashref of vars to the template, returning the processed string. >+ >+=cut >+ >+sub process_tt { >+ my ( $template, $vars ) = @_; >+ >+ if ( index( $template, '[%' ) != -1 ) { # Much faster than regex >+ my $use_template_cache = C4::Context->config('template_cache_dir') >+ && defined $ENV{GATEWAY_INTERFACE}; >+ >+ my $tt = 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 $schema = Koha::Database->new->schema; >+ my $output; >+ >+ $schema->txn_begin; >+ try { >+ $tt->process( \$template, $vars, \$output ); >+ } >+ catch { >+ croak "ERROR PROCESSING TEMPLATE: $_ :: " . $template->error(); >+ } >+ finally { >+ $schema->txn_rollback; >+ }; >+ >+ return $output; >+ } else { >+ return $template; >+ } >+} >+ >+=head1 AUTHOR >+ >+Kyle M Hall <kyle@bywatersolutions.com> >+ >+=cut >+ >+1; >-- >2.30.2
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 33030
:
147085
|
147182
|
148076
|
150511
|
150512
|
153142
|
153143