1 This is a README file for all interested in the templating system used
2 by Koha. It contains guidelines ans descriptions, please feel free to
3 make comments and contributions to this file.
7 The advantage of a templating system is the separation of code and
8 design. It is much easier to read the HTML and get an imagination of
9 what it will look like without having it shattered by declarations and
10 functions. And it is also nicer being able to alter some functions
11 without worrying about the web design.
13 On the other hand, templating stands in contradiction on scripting the
14 procedural way; it forces object-oriented programming.
16 With templates Koha can be made fully skinnable: we speak of themes,
17 and can support different languages.
21 The short version: Instead of printing HTML from your script, you only
22 define some template parameters.
24 You design your HTML page without code in it, and where you need to
25 insert data generated by the script. You can pass this data from the
26 template parameters via special tags.
28 Indeed, there is a little more to know.
30 I recomend reading the documentation to the HTML::Template module.
31 You can obtain it from http://www.perldoc.com/cpan/HTML/Template.html
33 3. How is it implemented in Koha
35 Koha uses templates to handle different themes and languages. In
36 the CVS module "koha", there is a subdirectory for the design files:
37 koha-tmpl. This subdirectory can be checked out from CVS as if it
38 were a CVS module "koha-tmpl".
40 It contains two directories for the OPAC and the intranet templates:
41 opac-tmpl and intranet-tmpl.
43 Each of this directories reflects the available themes and their
44 languages. The default theme is "default" and the default language is
45 "en" (we use the 2-letter abbreviations, en => English, fr => French,
46 de => German and so on).
48 If you, for example, want to write a template for the OPAC
49 part of the "custommade" theme in Polish, it has to go in
50 koha-tmpl/opac-tmpl/custommade/pl/template.tmpl.
52 The template files will not reside in your web tree. If
53 you want to use an image, you have to put this in your web
54 tree, which is organized the same way as the template tree
55 (koha-html/opac-html/custommade/pl/images/image.gif).
57 If you have files (either templates or files in the webspace)
58 which are the same for all themes or languages use the
59 "all" directory. For example the "background.jpg" image, which
60 is the same for all languages within a theme should go in
61 koha-html/(intranet|opac)-html/custommade/all/images/background.jpg).
65 Simply add an entry to the systempreferences: name=theme,
68 If you want your users be able to override your theme settings enter
69 name=allowthemeoverride value=customtheme1,customtheme2,... (names of
70 themes you want to be allowed) to the preferences.
72 For the language you normally don't have to enter anything, the
73 preferences of the user's browser will be used.
75 If anything is wrong you can specify a languageorder with the
76 following entry: name=languageorder value=en,fr,de,es (or whatever
77 comma-separated languages you want)
79 If you want to specify a directory for the templates you can do so in
80 koha.conf with 'templatedirectory=younameit'.
86 - Use absolute paths; relative paths in HTML tags would be relative to
87 the script's position and relative paths in <TMPL_INCLUDE> would be
88 relative to the template.
90 - You don't have to make templates for everything in your custom theme
91 or language. If you omit a template in a language, the template of
92 next available language is used. (Languages are tried in the order of
93 the user's browser settings.)
95 If there is no template in the specified language in a theme, a
96 different language will be chosen and NOT a different theme.
98 If you omit a template in all languages, the template of the default
101 - Include comments with useful information such as the template's
102 location; this simplifies debugging
104 - Use the same name for the template and the script (with different
105 extensions of course)
109 - Use meaningful English (abbreviations) as parameter names
111 - If you fetch a list of data, pass it completely and let the designer
112 decide which data to use.
114 - Working with arrays and loops is always better, even if you have
115 only three similar rows.
117 - Don't let the script generate html and pass the output to the
120 6. Templating stuff in Koha
122 This section is to describe scripts, modules and functions within them
123 to handle with themes, languages and other templating stuff.
125 If you write something which matches this, please add a brief
126 description here (e.g. function calls and return values).
128 - function %path = pathtotemplate(%hash) in C4::Output
130 Takes a hash with the following keys:
132 -template: the name of the template file (e.g. 'mytemplate.tmpl')
134 -type: 'opac', 'intranet', 'none' or something you specify, decides
135 which directory to lookup; defaults to intranet
137 -'opac': /somedirs/opac-tmpl/theme/language/template.tmpl
139 -'intranet': /somedirs/intranet-tmpl/theme/language/template.tmpl
141 -'none': /somedirs/theme/language/template.tmpl
143 -'my own words': /somedirs/my own
144 words/theme/language/template.tmpl
146 somedirs is 1. the path-parameter if specified 2. the
147 templatedirectory in koha.conf, 3. the includes + '/templates', 4.
150 -theme: you can manually set a theme (e.g. 'customtheme') only if
151 'allowthemeoverride' in systempreferences is set
153 -language: you can manually set a language (e.g. 'es')
155 -path: you can manually set the path to search for templates (e.g.
156 '/usr/koha/sometesttemplates')
158 You only need to pass the last three parameters if you want to
159 override the preferences for some reasons
163 - $path{'path'}: the complete+absolute path of the template (e.g.
164 '/somedirs.../opac-tmpl/customtheme/es/mytemplate.tmpl')
166 - $path{'fondlanguage'}: '1' if the requested template was available
167 in the requested language
169 - $path{'fondtheme'}: '1' if the requested template was available in
174 Do you have good links for the templater?
176 The HTML::Template documentation:
177 http://www.perldoc.com/cpan/HTML/Template.html
180 Comments to dnmeid@gmx.de Dorian