Table of Contents
When people want to find things in your Evergreen system, they will check the catalog. In Evergreen, the catalog is made available through a web interface, called the OPAC (Online Public Access Catalog). In the latest versions of the Evergreen system, the OPAC is built on a set of programming modules called the Template Toolkit. You will see the OPAC sometimes referred to as the TPAC.
In this chapter, we’ll show you how to customize the OPAC, change it from its default configuration, and make it your own.
The public interface is referred to as the TPAC or Template Toolkit (TT) within the Evergreen community. The template toolkit system allows you to customize the look and feel of your OPAC by editing the template pages (.tt2) files as well as the associated style sheets.
The default URL for the TPAC on a default Evergreen system is http://localhost/eg/opac/home (adjust localhost to match your hostname or IP address).
The default template file is installed in /openils/var/templates/opac.
You should generally avoid touching the installed default template files, unless you are contributing changes for Evergreen to adopt as a new default. Even then, while you are developing your changes, consider using template overrides rather than touching the installed templates until you are ready to commit the changes to a branch. See below for information on template overrides.
The mapping for templates to URLs is straightforward. Following are a few examples, where <templates> is a placeholder for one or more directories that will be searched for a match:
The template files themselves can process, be wrapped by, or include other template files. For example, the home.tt2 template currently involves a number of other template files to generate a single HTML file.
Example Template Toolkit file: opac/home.tt2.
[% PROCESS "opac/parts/header.tt2"; WRAPPER "opac/parts/base.tt2"; INCLUDE "opac/parts/topnav.tt2"; ctx.page_title = l("Home") %] <div id="search-wrapper"> [% INCLUDE "opac/parts/searchbar.tt2" %] </div> <div id="content-wrapper"> <div id="main-content-home"> <div class="common-full-pad"></div> [% INCLUDE "opac/parts/homesearch.tt2" %] <div class="common-full-pad"></div> </div> </div> [% END %]
Note that file references are relative to the top of the template directory.
Overrides for template files or TPAC pages go in a directory that parallels the structure of the default templates directory. The overrides then get pulled in via the Apache configuration.
The following example demonstrates how to create a file that overrides the default "Advanced search page" (advanced.tt2) by adding a new templates_custom directory and editing the new file in that directory.
bash$ mkdir -p /openils/var/templates_custom/opac bash$ cp /openils/var/templates/opac/advanced.tt2 \ /openils/var/templates_custom/opac/. bash$ vim /openils/var/templates_custom/opac/advanced.tt2
You now need to teach Apache about the new custom template directory. Edit /etc/apache2/sites-available/eg.conf and add the following <Location /eg> element to each of the <VirtualHost> elements in which you want to include the overrides. The default Evergreen configuration includes a VirtualHost directive for port 80 (HTTP) and another one for port 443 (HTTPS); you probably want to edit both, unless you want the HTTP user experience to be different from the HTTPS user experience.
<VirtualHost *:80> # <snip> # - absorb the shared virtual host settings Include eg_vhost.conf <Location /eg> PerlAddVar OILSWebTemplatePath "/openils/var/templates_custom" </Location> # <snip> </VirtualHost>
Finally, reload the Apache configuration to pick up the changes. You should now be able to see your change at http://localhost/eg/opac/advanced where localhost is the hostname of your Evergreen server.
You may adjust the colors of your public interface by editing the colors.tt2 file. The location of this file is in /openils/var/templates/opac/parts/css/colors.tt2. When you customize the colors of your public interface, remember to create a custom file in your custom template folder and edit the custom file and not the file located in you default template.
Font sizes can be changed in the colors.tt2 file located in /openils/var/templates/opac/parts/css/. Again, create and edit a custom template version and not the file in the default template.
Other aspects of fonts such as the default font family can be adjusted in /openils/var/templates/opac/css/style.css.tt2.
The media files (mostly PNG images) used by the default TPAC templates are stored in the repository in Open-ILS/web/images/ and installed in /openils/var/web/images/.
Out of the box, TPAC includes a number of placeholder text and links. For example, there is a set of links cleverly named Link 1, Link 2, and so on in the header and footer of every page in TPAC. Here is how to customize that for a custom templates skin.
To begin with, find the page(s) that contain the text in question. The simplest way to do that is with the grep -s command. In the following example, search for files that contain the text "Link 1":
bash$ grep -r "Link 1" /openils/var/templates/opac /openils/var/templates/opac/parts/topnav_links.tt2 4: <a href="http://example.com">[% l('Link 1') %]</a>
Next, copy the file into our overrides directory and edit it with vim.
Copying the links file into the overrides directory.
bash$ cp /openils/var/templates/opac/parts/topnav_links.tt2 \ /openils/var/templates_custom/opac/parts/topnav_links.tt2 bash$ vim /openils/var/templates_custom/opac/parts/topnav_links.tt2
Finally, edit the link text in opac/parts/header.tt2. Content of the opac/parts/header.tt2 file.
<div id="gold-links-holder"> <div id="gold-links"> <div id="header-links"> <a href="http://example.com">[% l('Link 1') %]</a> <a href="http://example.com">[% l('Link 2') %]</a> <a href="http://example.com">[% l('Link 3') %]</a> <a href="http://example.com">[% l('Link 4') %]</a> <a href="http://example.com">[% l('Link 5') %]</a> </div> </div> </div>
For the most part, the page looks like regular HTML, but note the [%(" ")%]_ that surrounds the text of each link. The [% … %] signifies a TT block, which can contain one or more TT processing instructions. l(" … "); is a function that marks text for localization (translation); a separate process can subsequently extract localized text as GNU gettext-formatted PO (Portable Object) files.
As Evergreen supports multiple languages, any customization to Evergreen’s default text must use the localization function. Also, note that the localization function supports placeholders such as [_1], [_2] in the text; these are replaced by the contents of variables passed as extra arguments to the l() function.
Once the link and link text has been edited to your satisfaction, load the page in a Web browser and see the live changes immediately.
It is possible to add and remove the MARC fields and subfields displayed in the record details page. In order to add MARC fields to be displayed on the details page of a record, you will need to map the MARC code to variables in the /openils/var/templates/opac/parts/misc_util.tt2 file.
For example, to map the template variable args.pubdates to the date of publication MARC field 260, subfield c, add these lines to misc_util.tt2:
args.pubdates = []; FOR sub IN xml.findnodes('//*[@tag="260"]/*[@code="c"]'); args.pubdates.push(sub.textContent); END; args.pubdate = (args.pubdates.size) ? args.pubdates.0 : ''
You will then need to edit the /openils/var/templates/opac/parts/record/summary.tt2 file in order to get the template variable for the MARC field to display.
For example, to display the date of publication code you created in the misc_util.tt2 file, add these lines:
[% IF attrs.pubdate; %] <span itemprop="datePublished">[% attrs.pubdate | html; %]</span> [% END; %]
You can add any MARC field to your record details page. Moreover, this approach can also be used to display MARC fields in other pages, such as your results page.