# Templates will be loaded from the following paths in reverse order.
PerlAddVar OILSWebTemplatePath "/openils/var/templates"
PerlAddVar OILSWebTemplatePath "/openils/var/my_own_templates"
* You can, for example, customize skins on the basis of the hostname being used via virtual hosts; note that the base template directory gets loaded first in eg_vhost.conf, so you're just specifying the customizations here:
ServerName myhostname
DocumentRoot /openils/var/web/
DirectoryIndex index.xml index.html index.xhtml
Include eg_vhost.conf
PerlAddVar OILSWebTemplatePath "/openils/var/my_own_templates"
* Place your version of all ''.tt2'' files that you would edit into a directory structure that mirrors that of the stock template path. That is, if you want to have your own version of ''/openils/var/templates/default/opac/parts/topnav.tt2'', put it at ''/openils/var/**my_own_templates**/default/opac/parts/topnav.tt2''.
* Do **not** copy every file under ''/openils/var/templates'' into ''my_own_templates'' -- that is not necessary.
* Reload Apache.
=== String Localization ===
* Create a ''.po'' file for your locale. Requires the ''Locale::Maketext::Extract::Plugin::TT2'' Perl module:
sudo -u opensrf xgettext.pl --plugin=tt2 --directory=Open-ILS/src/templates/opac/ --output-dir=/openils/var/templates/locale --output=tpac.fr_CA.po
* Add your .po file to the Apache ''eg_vhost.conf'' file in the ''
PerlAddVar OILSWebLocale "en_ca"
PerlAddVar OILSWebLocale "/openils/var/templates/locale/tpac.en_CA.po"
PerlAddVar OILSWebLocale "fr_ca"
PerlAddVar OILSWebLocale "/openils/var/templates/locale/tpac.fr_CA.po"
* Edit strings in your new .po file. For example:
...
#: Open-ILS/src/templates/opac/parts/topnav.tt2:34
msgid "My Account"
msgstr "Mon compte"
...
* Reload Apache. (Translations are cached in the browser)
* To test, reload the page with fr-CA as the browser's default locale
=== Custom Perl Handler ===
It's possible to override specific behavior of the default OPAC mod_perl handler by sub-classing the default and selecting methods to override.
* Create a local Perl module that is a subclass of OpenILS::WWW::EGCatLoader. Example:
package EGCatLoaderLocal;
use base 'OpenILS::WWW::EGCatLoader';
# override a single method
sub redirect_auth {
my $self = shift;
return $self->generic_redirect("http://my-fancy-auth-service.example.org");
}
* Configure the new Perl module as the OPAC handler in Apache
#PerlSetVar OILSWebContextLoader "OpenILS::WWW::EGCatLoader"
PerlSetVar OILSWebContextLoader "EGCatLoaderLocal"
* Reload Apache
===== Development conventions =====
* Use the localization macro (''l()'') to mark text that needs to be translated:
[% l('Search results') %]
The localization macro accepts parameters so that you can create complex strings that represent a complete sentence or translatable phrase. In the following example, variable ''[_1]'' is replaced by the value of the first argument, //user_name//, and ''[_2]'' is replaced by the value of the second argument, //library_name//:
[% l('Hello [_1]! You are browsing the [_2] catalog', user_name, library_name) %]
* Escape output to prevent XSS vulnerabilities and broken HTML.Use the ''html'' filter to escape text generated from outside of the template in HTML, and the ''uri'' filter to escape URIs. For example, in the following example the text in the first table cell is not escaped because it is static text from the template itself, while the **attrs.author** text comes from the database and therefore should be escaped:
[% l("Author:") %]' [% attrs.author | html %]
Note that the ''uri'' filter is not necessary in cases where the URI has passed through the CGI plugin, such as in the ''mkurl()'' macro.