Notices with Template Toolkit

From Koha Wiki

Jump to: navigation, search
Home > Documentation


General notes

  • Template Toolkit syntax is available for all notices, but not all information might be available yet
  • New notices often will have a default TT template and can't be rewritten to the old syntax with the same functionality
  • You can mix an match (use hungry alligators <<biblio.title>> together with TT syntax) in one notice template

Template Toolkit documentation:

Examples: Notices and slips using Template Toolkit

Make choices

Check for existence of a field in order to only print it if it exists:

[% IF %] Author: [% %] [% END %]

You can also make some choices using else and if:

[% IF %]
[% ELSE %]
[% END %]

If you have more then 2 choices:

[% IF something %]
[% ELSIF something2 %]
[% ELSIF something3 %]
[% ELSE %]
[% END %]


You need to know the variable name for the notice in order to be able to loop through information.

[% FOR item IN biblio.items %]
[% item.itemcallnumber %], [% item.barcode %]
[% END %]

Example: Overdue notices

Have access to: biblio, biblioitems, items, issues

Old syntax:

<item>"<<biblio.title>>" by <<>>, <<items.itemcallnumber>>, Barcode: <<items.barcode>></item>


[% FOREACH overdue IN overdues %]
[%~ SET item = overdue.item ~%]
"[% item.biblio.title %]" by [% %], [% item.itemcallnumber %], Barcode: [% item.barcode %]
[% END %]

Make this look nicer by using IF constructs.

Using filters

Example: Format dates

You don't have to put the use statements in the notices, but it's recommended. So if you want to use date formatting, you put a

[%- USE Kohadates -%]
Date due without hours: [% overdue.date_due | $KohaDates %]
Date due with hours: [% overdue.date_due | $KohaDates with_hours => 1 %]

Example: Format prices

Uses CurrencyFormat and active currency:

[%- USE Price -%]
[% items.price | $Price %]

More filters

There are Koha specific filters like above, but TT also comes with a lot of standard filters:

Filters available by default

There are some plugins available by default in each notice template

  • KohaDates (use as filter: "somedate | $KohaDates" )
  • Remove_MARC_punctuation (use as filter: "somevariable| $Remove_MARC_punctuation" )

The $Remove_MARC_punctuation filter is even used automatically for these variables:

  • biblio.*
  • biblioitem.*

Use Plugins

[%- Use Biblio -%]
Holds: [% Biblio.HoldsCount(biblio.biblionumber) %]
[% IF Biblio.HoldsCount(biblio.biblionumber) > 1 %]
There is more than one person waiting for this item, please return it!
[% END %]

Also available: Borrowers, Branches, Itemtypes (To be documented)

Using variables

Variables available

One object reference Set of objects reference Type Note
today Special variable with current date and time
article_request article_requests Koha::ArticleRequests
biblio biblios Koha::Biblios
biblioitem biblioitems Koha::Biblioitems
borrower borrowers Koha::Patrons
branch branches Koha::Libraries
item items Koha::Items
news news Koha::News News for OPAC
order orders Koha::Acquisition::Orders
hold holds Koha::Holds
serial serials Koha::Serials These are issues added using serials module
subscription subscriptions Koha::Subscriptions
suggestion suggestions Koha::Suggestions
checkout checkouts Koha::Checkouts
old_checkout old_checkouts Koha::Old::Checkouts
overdue overdues Koha::Checkouts
patron_modification patron_modifications Koha::Patron::Modifications
credit Koha::Account::Line Used in ACCOUNT_PAYMENT, ACCOUNT_WRITEOFF
offsets Array of Koha::Account::Offset Used in ACCOUNT_PAYMENT, ACCOUNT_WRITEOFF
passwordreseturl string with url to reset password Used in PASSWORD_RESET
user Patron's userid (login) Used in PASSWORD_RESET
items.content concatenated strings returned by C4::Letters::get_item_content Used in DUE, PREDUE, DUEDGST, PREDUEDGST
count count of checkouts Used in DUEDGST, PREDUEDGST
listname string of name of list to be shared Used in SHARE_ACCEPT, SHARE_INVITE
shareurl string of url to shared list Used in SHARE_INVITE

Variables available in each notice

Notice code List of available object variables List of available set variables Variables available only in old syntax
ACQ_NOTIF_ON_RECEIV branch, borrower, biblio, order
CHECKOUT item, biblio, biblioitem, borrower, branch, checkout
CHECKIN item, biblio, biblioitem, borrower, branch, old_checkout
RENEWAL item, biblio, biblioitem, borrower, branch, checkout
TRANSFERSLIP branch, biblio, item
Claim notice in serials module, branch aqbooksellers, aqcontacts
Claim notice in acquisition, default is ACQCLAIM branch aqbooksellers, aqcontacts
ACQORDER branch aqbooksellers, aqcontacts
Notice about new serial issue, default is SERIAL_ALERT branch, biblio, biblioitem, borrower, subscription, serial
ACCTDETAILS, send to patrons when their account is created branch, borrower
ISSUESLIP branch, borrower checkouts, overdues, news
ISSUEQSLIP branch, borrower checkouts
OVERDUES_SLIP borrower, branch (could be unavailable, depends on context) overdues
HOLDPLACED branch, borrower, biblio, biblioitem, item, hold
HOLD, sent when message is waiting, code defined in message_transports db table branch, borrower, biblio, biblioitem, item, hold
HOLD_SLIP branch, borrower, biblio, biblioitem, item, hold
HOLDPLACED branch, borrower, biblio, biblioitem, item, hold/
Sugguestion status notices: ACCEPTED, AVAILABLE, ORDERED, REJECTED, ASKED, CHECKED branch, borrower, suggestion, biblio
TO_PROCESS suggestion, branch, borrower
ACCOUNT_PAYMENT, ACCOUNT_WRITEOFF borrower, branch, credit offsets
Article requests notices: AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED, AR_SLIP article_request, borrower, biblio, biblioitem, item, branch
DISCHARGE borrower, branch
PASSWORD_RESET passwordreseturl, user
CANCEL_HOLD_ON_LOST branch, borrower, item, biblio, biblioitem, hold
DUE, PREDUE borrower, branch, biblio, biblioitem, item, checkout, items.content
PREDUEDGST, DUEDGST borrower, branch, count, items.content, all columns of branches table as branches.* variable
AUTO_RENEWALS borrower, checkout, item, biblio
MEMBERSHIP_EXPIRY borrower, branch
SR_SLIP branch.code,,,, branch.items, branch.log
PREDUE, OVERDUE, HOLD for phone type notices borrower, biblio, biblioitem
CHECKOUT_NOTE biblio, borrower, checkout (only when used through svc)
OPAC_REG_VERIFY borrower_modification
SHARE_ACCEPT borrower, listname
SHARE_INVITE borrower, listname, shareurl
Personal tools