Bugzilla – Attachment 91374 Details for
Bug 23237
Add support for [% INCLUDE %] in plugin templates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23237 Plugin allow [% INCLUDE %] from template
Bug-23237-Plugin-allow--INCLUDE--from-template.patch (text/plain), 3.39 KB, created by
Maryse Simard
on 2019-07-05 20:11:24 UTC
(
hide
)
Description:
Bug 23237 Plugin allow [% INCLUDE %] from template
Filename:
MIME Type:
Creator:
Maryse Simard
Created:
2019-07-05 20:11:24 UTC
Size:
3.39 KB
patch
obsolete
>From 5b98ed42b896470a93da6c644e54f93bd52ccd5b Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= <f.demians@tamil.fr> >Date: Sat, 29 Jun 2019 08:55:34 +0200 >Subject: [PATCH] Bug 23237 Plugin allow [% INCLUDE %] from template >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >From a plugin template it is useful to be able to include other templates with >[% INCLUDE %] directives. But TT module is used by Koha with absolute paths. >Relative paths are forbidden for security reasons. A new param [% PLUGIN_DIR %] >allow plugin templates to know where to find plugin home directory. > >How to test: > >1. Install kitchen-sink plugin. > >2. Find tool-step1.tt file, and add this at the begining of the file: > [% INCLUDE "$PLUGIN_DIR/header.tt" %] > It ask to include a template header.tt which doesn't exit. > >3. Run kitchen-sink plugin tool. You must have this error message: > > Template process failed: file error - _path to plugin > directory_/Koha/Plugin/Com/ByWaterSolutions/KitchenSink/header.tt: not found > > quod erat demonstrandum > >Signed-off-by: Maryse Simard <maryse.simard@inlibro.com> >--- > Koha/Plugins/Base.pm | 48 +++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 47 insertions(+), 1 deletion(-) > >diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm >index 059c673..75a7402 100644 >--- a/Koha/Plugins/Base.pm >+++ b/Koha/Plugins/Base.pm >@@ -119,6 +119,32 @@ sub retrieve_data { > get_template returns a Template object. Eventually this will probably be calling > C4:Template, but at the moment, it does not. > >+The returned template contains 3 variables that can be used in the plugin >+templates: >+ >+=over 8 >+ >+=item B<CLASS> >+ >+The name of the plugin class. >+ >+=item B<METHOD> >+ >+Then name of the plugin method used. For example 'tool' or 'report'. >+ >+=item B<PLUGIN_PATH> >+ >+The URL path to the plugin. It can be used in templates in order to localize >+ressources like images in html tags, or other templates. >+ >+=item B<PLUGN_DIR> >+ >+The absolute pathname to the plugin directory. Necessary to include other >+templates from a template with the [% INCLUDE %] directive. >+ >+=over >+ >+ > =cut > > sub get_template { >@@ -142,6 +168,7 @@ sub get_template { > CLASS => $self->{'class'}, > METHOD => scalar $self->{'cgi'}->param('method'), > PLUGIN_PATH => $self->get_plugin_http_path(), >+ PLUGIN_DIR => $self->get_plugin_dir(), > ); > > return $template; >@@ -150,7 +177,10 @@ sub get_template { > sub get_metadata { > my ( $self, $args ) = @_; > >- return $self->{'metadata'}; >+ #FIXME: Why another encoding issue? For metadata containg non latin characters. >+ my $metadata = $self->{metadata}; >+ utf8::decode($metadata->{$_}) for keys %$metadata; >+ return $metadata; > } > > =head2 get_qualified_table_name >@@ -185,6 +215,22 @@ sub get_plugin_http_path { > return "/plugin/" . join( '/', split( '::', $self->{'class'} ) ); > } > >+=head2 get_plugin_dir >+ >+To [% INCLUDE %] another TT template from a template, an absolute path to the >+template is required. This method returns that absolute file system path. >+ >+usage: my $path = $self->get_plugin_dir(); >+ >+=cut >+ >+sub get_plugin_dir { >+ my ($self) = @_; >+ >+ my $base = C4::Context->config('pluginsdir'); >+ return "$base/" . join( '/', split( '::', $self->{'class'} ) ); >+} >+ > =head2 go_home > > go_home is a quick redirect to the Koha plugins home page >-- >2.7.4
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 23237
:
91128
|
91374
|
91875
|
91876
|
97862