Summary: | Add Template::Toolkit WRAPPER for Koha Tool Plugins | ||
---|---|---|---|
Product: | Koha | Reporter: | David Cook <dcook> |
Component: | Plugin architecture | Assignee: | David Cook <dcook> |
Status: | CLOSED FIXED | QA Contact: | Testopia <testopia> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | kyle, matt.blenkinsop, paul.derscheid, tomascohen |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: |
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30289 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31380 |
||
GIT URL: | Change sponsored?: | --- | |
Patch complexity: | --- | Documentation contact: | |
Documentation submission: | Text to go in the release notes: | ||
Version(s) released in: |
23.11.00,23.05.02
|
Circulation function: | |
Bug Depends on: | |||
Bug Blocks: | 34307 | ||
Attachments: |
Bug 31339: Add staff wrapper template include for tool plugins
test plugin Bug 31339: Add staff wrapper template include for tool plugins Bug 31339: Add staff wrapper template include for tool plugins |
Description
David Cook
2022-08-11 06:18:02 UTC
Here's an example for a tool plugin: [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] <title>Plugins › Tools › Koha </title> [% INCLUDE 'doc-head-close.inc' %] </head> <body> [% INCLUDE 'header.inc' %] [% INCLUDE 'prefs-admin-search.inc' %] <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb"> <ol> <li> <a href="/cgi-bin/koha/mainpage.pl">Home</a> </li> <li> <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> </li> <li> <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> </li> <li> <a href="#" aria-current="page"> Plugin </a> </li> </ol> </nav> <div class="main container-fluid"> <div class="row"> <div class="col-sm-10 col-sm-push-2"> <main> [% content %] </main> </div> <!-- /.col-sm-10.col-sm-push-2 --> <div class="col-sm-2 col-sm-pull-10"> <aside> [% INCLUDE 'tools-menu.inc' %] </aside> </div> <!-- /.col-sm-2.col-sm-pull-10 --> </div> <!-- /.row --> [% INCLUDE 'intranet-bottom.inc' %] For the moment, I'm including this wrapper template in my Koha plugin. In my .pm file I do this: my $wrapper_path = abs_path( $self->mbf_path( 'plugin-staff-wrapper.tt' ) ); $template->{VARS}->{wrapper_path} = $wrapper_path; Then for each individual template I need for specific functionality, I can just do this: [% WRAPPER "$wrapper_path" %] <h1>Plugin Name</h1> [% END %] -- Even if the wrapper isn't included in Koha core, it could mean updating just the 1 wrapper template instead of updating every single template file because there's a new header include needed or something. I love this approach. I could look it up myself but can you pass props to wrappers? (In reply to Paul Derscheid from comment #3) > I love this approach. Glad to hear it! > I could look it up myself but can you pass props to wrappers? You can! I was going to do a better example, but I was running out of time last night hehe. If you look at https://bugs.koha-community.org/bugzilla3/page.cgi?id=splinter.html&bug=30289&attachment=133074 you can see I'm passing in "bodyid", "breadcrumb_label", "columns", and "include_navigation" to the wrapper. In that case, I'm just passing strings, but you can pass variables too. You can define your jsinclude and cssinclude blocks in your individual pages and they'll still be processed via the includes in the wrapper. So it's quite flexible and very powerful. Created attachment 139647 [details] [review] Bug 31339: Add staff wrapper template include for tool plugins This change adds a template include which can be used as a WRAPPER for tool plugins, which makes it easy to pages in tool templates without having to copy and maintain a lot of template boilerplate. Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Upload koha-plugin-test-wrapper 2. Enable the plugin 3. Click "Actions" and click "Run tool" 4. Note how the plugin page looks like a perfect Koha Tools page 5. Note that the plugin only contains 6 lines of template code to achieve this effect Created attachment 139648 [details]
test plugin
Created attachment 150528 [details] [review] Bug 31339: Add staff wrapper template include for tool plugins This change adds a template include which can be used as a WRAPPER for tool plugins, which makes it easy to pages in tool templates without having to copy and maintain a lot of template boilerplate. Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Upload koha-plugin-test-wrapper 2. Enable the plugin 3. Click "Actions" and click "Run tool" 4. Note how the plugin page looks like a perfect Koha Tools page 5. Note that the plugin only contains 6 lines of template code to achieve this effect Signed-off-by: David Nind <david@davidnind.com> Created attachment 153201 [details] [review] Bug 31339: Add staff wrapper template include for tool plugins This change adds a template include which can be used as a WRAPPER for tool plugins, which makes it easy to pages in tool templates without having to copy and maintain a lot of template boilerplate. Test plan: 0. Apply patch and koha-plack --restart kohadev 1. Upload koha-plugin-test-wrapper 2. Enable the plugin 3. Click "Actions" and click "Run tool" 4. Note how the plugin page looks like a perfect Koha Tools page 5. Note that the plugin only contains 6 lines of template code to achieve this effect Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Cheers, guys! I haven't tried this out since the staff-side re-vamp, so it's cool to hear that this is still working as expected. David, I'm pushing this one but please look at (for example) bug 33599, to see how the breadcrumbs should be built using the new wrapper Owen introduced. And file a bug for fixing it. Thanks! Pushed to master for 23.11. Nice work everyone, thanks! (In reply to Tomás Cohen Arazi from comment #10) > David, I'm pushing this one but please look at (for example) bug 33599, to > see how the breadcrumbs should be built using the new wrapper Owen > introduced. > > And file a bug for fixing it. Thanks! Will do! Thanks! (In reply to David Cook from comment #12) > (In reply to Tomás Cohen Arazi from comment #10) > > David, I'm pushing this one but please look at (for example) bug 33599, to > > see how the breadcrumbs should be built using the new wrapper Owen > > introduced. > > > > And file a bug for fixing it. Thanks! > > Will do! Thanks! That's all ready to go on bug 34307 now. Thanks for all the hard work! Pushed to 23.05.x for the next release Enhancement - not backporting to 22.11.x |