Bug 26381 - Koha should provide Koha plugins with a template to use with Template::Toolkit WRAPPER
Summary: Koha should provide Koha plugins with a template to use with Template::Toolki...
Status: RESOLVED DUPLICATE of bug 30289
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: David Cook
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-04 06:01 UTC by David Cook
Modified: 2022-04-07 11:39 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2020-09-04 06:01:52 UTC
At the moment, Koha plugins have to built their own templates from scratch. 

I'm proposing that Koha provides a BLOCK or a template file that Koha plugins can then use with the Template::Toolkit WRAPPER directive to minimize the amount of boiler plate they have to use. 

Here is an example of a very simple "plugin_wrapper"

[% BLOCK plugin_wrapper %]
[% INCLUDE 'doc-head-open.inc' %]
    <title>Koha: [% name %]</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> &rsaquo; [% breadcrumb %]</div>
<div id="doc3">
[% content %]
[% INCLUDE 'intranet-bottom.inc' %]
[% END %]

Then, in my report-step1.tt file, all I need to include is the following:

[% WRAPPER plugin_wrapper
    name = 'My Plugin'
    breadcrumb = 'My Plugin'
%]
<div>Plugin content</div>
[% END %]

I've already tested this a little bit, and it's beautiful.
Comment 1 David Cook 2020-09-04 06:04:18 UTC
This could make it easier to support Koha plugins across multiple versions, since the different Koha versions would provide their own wrappers.

(I admit that this could maybe create compatibility issues if the Koha plugin HTML isn't written well or somehow conflicts with the mainstream Koha wrapper.)
Comment 2 David Cook 2020-09-04 06:07:00 UTC
I think that I could also be happy with Koha plugin specific wrappers, so long as they could be reusable within the same plugin. 

I need to play with the INCLUDE directive a bit to see whether or not Koha needs to be patched to add include directories for plugins...
Comment 3 David Cook 2020-09-04 06:21:32 UTC
(In reply to David Cook from comment #2)
> I think that I could also be happy with Koha plugin specific wrappers, so
> long as they could be reusable within the same plugin. 
> 
> I need to play with the INCLUDE directive a bit to see whether or not Koha
> needs to be patched to add include directories for plugins...

Here's a solution:

MyPlugin.pm:
my $template = $self->get_template({ file => 'report-step1.tt' });
my $wrapper = $self->mbf_path('wrapper.tt');
$template->param( plugin_wrapper => $wrapper, );

report-step1.tt:
[% WRAPPER $plugin_wrapper
    name = 'My Plugin'
    breadcrumb = 'My Plugin'
%]
<div>Plugin content</div>
[% END %]

Excellent!

There's other ways we could do this, but that worked pretty well.
Comment 4 David Cook 2020-09-04 06:56:12 UTC
Actually, here is a more modern wrapper for a report plugin I think...

[% INCLUDE 'doc-head-open.inc' %]
    <title>Koha: [% name %]</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> &rsaquo; [% breadcrumb %]</div>
<div class="main container-fluid">
    <div class="row">
        <div class="col-sm-10 col-sm-push-2">
            <main>
                [% content %]
            </main>
        </div>
        <div class="col-sm-2 col-sm-pull-10">
            <aside>
                [% INCLUDE 'reports-menu.inc' %]
            </aside>
        </div>
    </div>
[% INCLUDE 'intranet-bottom.inc' %]
Comment 5 David Cook 2022-04-07 11:39:14 UTC
This is really a duplicate of bug 30289.

*** This bug has been marked as a duplicate of bug 30289 ***