1 of 18

Using All of the Tools in Your Kit

A user-focused introduction to Template Toolkit in Koha

2 of 18

What is Template Toolkit (TT)?

“The Template Toolkit is a fast, flexible and highly extensible template processing system.” - https://template-toolkit.org/

  • HTML builds a structure and adds static content
  • CSS applies styling
  • TT allows logic and variable content

3 of 18

Where is TT used in Koha?

  • Constructing pages
  • Notice & slip templates
  • MARC record customization
  • Assorted other features for formatting and displaying data

4 of 18

5 of 18

6 of 18

7 of 18

8 of 18

A brief discussion of objects and how TT uses them

9 of 18

How is a toolkit better than an alligator?

  • Access to more data
  • IF / UNLESS logic
  • Data manipulation/transformation
  • Koha template filters

10 of 18

An IF example

11 of 18

Debug, Troubleshooting, and Data::Dumper

[% USE Dumper %]�[% Dumper.dump_html( borrower )%]

[% Dumper.dump_html( borrower.unblessed )%]

12 of 18

A substr() example

Hold slip with partial name

13 of 18

A replace() example

14 of 18

Filter/format examples

[% borrower.surname | upper %]�[% borrower.dateexpiry | $KohaDates %]�[% some_html | html %]��[% borrower.dateexpiry | html | $KohaDates %]

15 of 18

Koha template plugins (helpers)

[% USE Price %]

[% item.replacementprice | $Price %] - magic with CurrencyFormat�[% item.replacementpricedate | $KohaDates %] - magic with DateFormat �[% biblio.title | $Remove_MARC_puncuation %]

16 of 18

Koha template plugins - Circulation rules

[% USE CirculationRules %]

[% FOREACH c IN borrower.checkouts %]

[% SET renewals = CirculationRules.Renewals( borrower.borrowernumber, c.itemnumber ) %] <br />

Renewals remaing: [% renewals.remaining %]

[% END %]

17 of 18

Koha template plugins -How did that work?

An example from Koha/Template/Plugin/CirculationRules.pm

18 of 18

Resources

  • Koha wiki
    • Notices and Slips Library
      • Includes examples of both full notices and useful phrases
    • Notices with Template Toolkit
      • Covers various filters and plugins; includes a list of data available in each notice
  • Template Toolkit documentation
    • Directives: syntax for conditional and list processing
    • VMethods: syntax for data manipulation and transformation
  • Open Fifth article on Template Toolkit in notices
  • Visual Studio Code
    • One of many free code editors