Bug 30289 - Use Template::Toolkit WRAPPER to reduce template boilerplate
Summary: Use Template::Toolkit WRAPPER to reduce template boilerplate
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: David Cook
QA Contact: Testopia
URL:
Keywords:
: 26381 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-03-14 05:54 UTC by David Cook
Modified: 2022-08-11 06:18 UTC (History)
3 users (show)

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


Attachments
Koha Wrapper Template Toolkit File (3.30 KB, text/plain)
2022-03-14 06:01 UTC, David Cook
Details
Bug 30289: Demonstrate using a WRAPPER with opac-library.pl (16.08 KB, patch)
2022-04-07 11:27 UTC, David Cook
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2022-03-14 05:54:42 UTC
If we used a Template::Toolkit WRAPPER directive, we could eliminate *a lot* of boiler plate from our templates and improve ease of maintenance. 

I suggest we start with the OPAC since it's smaller than the staff interface.
Comment 1 David Cook 2022-03-14 06:01:38 UTC
Created attachment 131649 [details]
Koha Wrapper Template Toolkit File

This is a first draft of a wrapper that can be used to provide the boiler plate for an OPAC page. 

Using the WRAPPER directive (http://www.template-toolkit.org/docs/manual/Directives.html#section_WRAPPER), we can reference it from opac-blah.tt using the following:

[% WRAPPER koha_wrapper.inc 
  bodyid="opac-blah"
  columns="two_leftside"
%]
This is my page content
[% END %]
Comment 2 David Cook 2022-03-14 06:03:21 UTC
Even if the community doesn't use this, I'm going to start using it for my own custom OPAC pages.
Comment 3 Marcel de Rooy 2022-03-14 08:13:04 UTC
Interesting. You might convince the community even more by implementing into various opac templates. Getting it to work with a bunch of templates should show how beneficial it is.
Comment 4 David Cook 2022-03-14 23:09:55 UTC
(In reply to Marcel de Rooy from comment #3)
> Interesting. You might convince the community even more by implementing into
> various opac templates. Getting it to work with a bunch of templates should
> show how beneficial it is.

I was thinking the same thing, although I figure they need to be low-risk changes to be accepted. 

Maybe opac-library.pl and opac-tags.pl? 

I was also thinking I need to convince Owen most of all 😅.
Comment 5 David Cook 2022-04-07 11:27:17 UTC
Created attachment 133074 [details] [review]
Bug 30289: Demonstrate using a WRAPPER with opac-library.pl

This patch replaces template boiler plate by using the
Template::Toolkit directive WRAPPER.

Test plan:
1. Go to http://localhost:8080/cgi-bin/koha/opac-library.pl
2. Outputs a list of libraries
3. Go to http://localhost:8080/cgi-bin/koha/opac-library.pl?branchcode=CPL
4. Outputs details for Centerville library only

FIXME: I still need to improve the handling of the <title> element
and the breadcrumbs, but those shouldn't be too challenging.
Comment 6 David Cook 2022-04-07 11:39:14 UTC
*** Bug 26381 has been marked as a duplicate of this bug. ***
Comment 7 David Cook 2022-04-07 11:42:49 UTC
(In reply to David Cook from comment #6)
> *** Bug 26381 has been marked as a duplicate of this bug. ***

I just remembered that it would be useful for Koha plugins too if they could refer to a WRAPPER so that they just worried about the core content to fill in the page.
Comment 8 David Cook 2022-04-20 01:16:20 UTC
This isn't quite ready for sign off, but I'd like to get Owen's feedback before progressing this further.
Comment 9 Jonathan Druart 2022-05-19 06:21:51 UTC
Owen what's your opinion on this?