Bug 23237 - Add support for [% INCLUDE %] in plugin templates
Summary: Add support for [% INCLUDE %] in plugin templates
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low new feature
Assignee: Frédéric Demians
QA Contact: Nick Clemens (kidclamp)
URL:
Keywords:
Depends on:
Blocks: 26803
  Show dependency treegraph
 
Reported: 2019-06-29 06:54 UTC by Frédéric Demians
Modified: 2021-06-14 21:29 UTC (History)
8 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
The new feature allows plugin authors to use template `[% INCLUDE %]` directives in their templates. It does so by introducing a new variable, `PLUGIN_DIR`, allowing the template engine to locate the includes. **Usage**: `[% INCLUDE "$PLUGIN_DIR/header.tt" %]` **Warning**: Care should be taken when installing any plugins and only plugins you trust should be used.
Version(s) released in:
19.11.00,19.05.03
Circulation function:


Attachments
Bug 23237 Plugin allow [% INCLUDE %] from template (3.33 KB, patch)
2019-06-29 07:10 UTC, Frédéric Demians
Details | Diff | Splinter Review
Bug 23237 Plugin allow [% INCLUDE %] from template (3.39 KB, patch)
2019-07-05 20:11 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 23237: Plugin allow [% INCLUDE %] from template (3.45 KB, patch)
2019-07-30 13:52 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 23237: Fix POD and typos (1.29 KB, patch)
2019-07-30 13:52 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 23237: Fix PLUGIN_DIR parameter in master/19.11 (1.81 KB, patch)
2020-01-24 09:22 UTC, Frédéric Demians
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric Demians 2019-06-29 06:54:58 UTC
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.
Comment 1 Frédéric Demians 2019-06-29 07:10:31 UTC
Created attachment 91128 [details] [review]
Bug 23237 Plugin allow [% INCLUDE %] from template

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
Comment 2 Maryse Simard 2019-07-05 20:11:24 UTC
Created attachment 91374 [details] [review]
Bug 23237 Plugin allow [% INCLUDE %] from template

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>
Comment 3 Nick Clemens (kidclamp) 2019-07-30 13:52:44 UTC
Created attachment 91875 [details] [review]
Bug 23237: Plugin allow [% INCLUDE %] from template

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>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 4 Nick Clemens (kidclamp) 2019-07-30 13:52:47 UTC
Created attachment 91876 [details] [review]
Bug 23237: Fix POD and typos

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 5 Martin Renvoize (ashimema) 2019-08-05 14:47:55 UTC
Nice work!

Pushed to master for 19.11.00
Comment 6 Martin Renvoize (ashimema) 2019-08-05 14:51:19 UTC
Nice work!

Pushed to master for 19.11.00
Comment 7 Fridolin Somers 2019-08-09 13:45:56 UTC
Nice enhancement.
I choose to backport so than Koha Plugins can already be developed/updated with this.

Pushed to 19.05.x for 19.05.03
Comment 8 Lucas Gass (lukeg) 2019-09-17 19:25:49 UTC
following Fridolin's lead and backporting this enhancement to 18.11.x for 18.11.10
Comment 9 Lucas Gass (lukeg) 2019-09-20 22:02:20 UTC
this patchset made me unable to prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t in 18.11.x, since this is an enhancement i am choosing to revert the patch set in 18.11.x
Comment 10 Tomás Cohen Arazi (tcohen) 2019-11-27 19:37:24 UTC
I think the get_plugin_dir method is not quite correct as there can be more than one plugins_dir entry. bundle_dir should be used instead.
Comment 11 Martin Renvoize (ashimema) 2020-01-21 17:06:20 UTC
Any further thoughts regarding Tomas's comment Frederic?
Comment 12 Frédéric Demians 2020-01-24 09:13:47 UTC
(In reply to Martin Renvoize from comment #11)
> Any further thoughts regarding Tomas's comment Frederic?

Thomas is right. I implemented this before Thomas added bundle_dir() method. I
will submit a patch to use Thomas method instead of mine get_plugin_dir()
method.

bundle_dir() is available in 19.11 and after. So the new patch must not be
backported to 19.05 and 18.11. As it is the usage of new template parameter
PLUGIN_DIR will be OK in 18.11 and 19.05 as soon as plugins_dir parameter is
unique in koha-conf.xml.
Comment 13 Frédéric Demians 2020-01-24 09:22:25 UTC
Created attachment 97862 [details] [review]
Bug 23237: Fix PLUGIN_DIR parameter in master/19.11

Method get_plugin_dir() is not correct when plugin_dirs parameter is repeated
in koha-conf.xml. A new method bundle_path() must be used instead.

bundle_dir() is available in 19.11 and after. So the new patch must not be
backported to 19.05 and 18.11. As it is the usage of the new template parameter
PLUGIN_DIR will be OK in 18.11 and 19.05 as soon as plugins_dir parameter is
unique in koha-conf.xml.

Thanks Thomas
Comment 14 Frédéric Demians 2020-10-23 16:20:26 UTC
See bug 26803