1 package Koha::TemplateUtils;
3 # Copyright ByWater Solutions 2023
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use vars qw(@ISA @EXPORT_OK);
33 @EXPORT_OK = qw( process_tt );
40 A module to centralize and standardize processing of template toolkit syntax
41 for uses other than slips and notices.
45 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.
49 $processed = process_tt($template, $vars);
51 Process the given Template Toolkit string, passing the given hashref of vars to the template, returning the processed string.
56 my ( $template, $vars ) = @_;
58 if ( index( $template, '[%' ) != -1 ) { # Much faster than regex
59 my $use_template_cache = C4::Context->config('template_cache_dir')
60 && defined $ENV{GATEWAY_INTERFACE};
62 my $tt = Template->new(
66 PLUGIN_BASE => 'Koha::Template::Plugin',
67 COMPILE_EXT => $use_template_cache ? '.ttc' : '',
68 COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
72 ) or die Template->error();
74 my $schema = Koha::Database->new->schema;
79 $tt->process( \$template, $vars, \$output );
81 croak "ERROR PROCESSING TEMPLATE: $_ :: " . $template->error();
83 $schema->txn_rollback;
94 Kyle M Hall <kyle@bywatersolutions.com>