From a74c99807b93ae058699546694f22d09eced0ebb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 17 Dec 2024 07:52:08 +0000 Subject: [PATCH] Bug 38723: Add LOAD_PLUGINS to Template tooling This patch adds the Koha, Asset, and raw TT plugins that are used throughout templates to the LOAD_PLUGINS directive on Template load.. this way we shouldn't need to keep adding them to the top of every TT file and include. --- C4/Letters.pm | 1 + C4/Templates.pm | 14 ++++++++------ Koha/TemplateUtils.pm | 15 ++++++++------- xt/author/valid-templates.t | 1 + 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index ce8ffda7e17..e8946e515f4 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1737,6 +1737,7 @@ sub _process_tt { EVAL_PERL => 1, ABSOLUTE => 1, PLUGIN_BASE => 'Koha::Template::Plugin', + LOAD_PLUGINS => [ 'Koha', 'Asset', 'raw' ], COMPILE_EXT => $use_template_cache ? '.ttc' : '', COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', INCLUDE_PATH => \@includes, diff --git a/C4/Templates.pm b/C4/Templates.pm index fb7d3e5cb56..542afe3c8db 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -71,14 +71,16 @@ sub new { # Do not use template cache if script is called from commandline my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; my $template = Template->new( - { EVAL_PERL => 1, + { + 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') : '', + PLUGIN_BASE => 'Koha::Template::Plugin', + LOAD_PLUGINS => [ 'Koha', 'Asset', 'raw' ], + COMPILE_EXT => $use_template_cache ? '.ttc' : '', + COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', INCLUDE_PATH => \@includes, - FILTERS => {}, - ENCODING => 'UTF-8', + FILTERS => {}, + ENCODING => 'UTF-8', } ) or die Template->error(); my $self = { diff --git a/Koha/TemplateUtils.pm b/Koha/TemplateUtils.pm index aafbaaa6bd3..c818da4e4e8 100644 --- a/Koha/TemplateUtils.pm +++ b/Koha/TemplateUtils.pm @@ -61,13 +61,14 @@ sub process_tt { 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', + EVAL_PERL => 1, + ABSOLUTE => 1, + PLUGIN_BASE => 'Koha::Template::Plugin', + LOAD_PLUGINS => [ 'Koha', 'Asset', 'raw' ], + 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(); diff --git a/xt/author/valid-templates.t b/xt/author/valid-templates.t index 3724d035756..de93b9493c8 100755 --- a/xt/author/valid-templates.t +++ b/xt/author/valid-templates.t @@ -127,6 +127,7 @@ sub create_template_test { ABSOLUTE => 1, INCLUDE_PATH => $includes, PLUGIN_BASE => 'Koha::Template::Plugin', + LOAD_PLUGINS => [ 'Koha', 'Asset', 'raw' ], } ); foreach my $exclusion (@exclusions) { -- 2.47.1