Initial revision
[koha.git] / koha-tmpl / templates.readme
1 This is a README-file for all interested in the templating system used by Koha.
2 It contains guidelines ans descriptions, please feel free to make comments and contributions to this file.
3   
4 1. Introduction
5   The advantage of a templating-system is the separation of code and design.
6   It is much easier to read the html and get an imagination of what it will look like without having it shattered by declarations and functions.
7   And it is also nicer being able to alter some functions without worrying about the webdesign.
8   On the other hand templating stands in contradiction on scripting the procedural way, it forces obect-oriented programming.
9   With templates Koha can be made fully skinnable, we speak of themes, and can support different languages.
10   
11 2. How does it work
12   The short version: Instead of printing html from your script you only define some template-parameters.
13   You design your html-page without code in it and where you need to insert data generated by the script you can pass this data from the template-parameters via special tags.
14   Indeed there is a little more to know.
15   I recomend reading the documentation to the HTML::Template-module.
16   You ca obtain it from http://www.perldoc.com/cpan/HTML/Template.html
17   
18 3. How is it implemented in Koha
19   Koha uses templates to handle different themes and languages.
20   There is a CVS-module for the design-files: koha-tmpl.
21   It contains two directories for the opac- and the intranet-templates: opac-tmpl and intranet-tmpl.
22   Each of this directories reflects the available themes and their languages.
23   The default theme is "default" and the default language is "en" (we use the 2letter-abbreviations, en => english, fr => french, de => german and so on).
24   If you for example want to write a template for the opac part of the "custommade"-theme in polish it has to go in koha-tmpl/opac-tmpl/custommade/pl/template.tmpl.
25   The template-files will not reside in your webtree, if you want to use a image you have to put this in your webtree, which is organized the same way as the templatetree (koha-html/opac-html/custommade/pl/images/image.gif).
26   If you have files (either templates or files in the webspace) which are the same for all themes or languages use the "all"-directory. For example the "background.jpg"-image, which is the same for all languages within a theme should go in koha-html/(intranet|opac)-html/custommade/all/images/background.jpg).
27   
28 4. How to use it
29   Simply add an entry to the systempreferences: name=theme, value=nameoftheme.
30   If you want your users be able to override your theme-settings enter name=allowthemeoverride value=customtheme1,customtheme2,... (names of themes you want to be allowed) to the preferences.
31   For the language you normally don't have to enter anything, the preferences of the user's browser will be used.
32   If anything is wrong you can specify a languageorder with the following entry: name=languageorder value=en,fr,de,es (or whatever comma-separated languages you want)
33   If you want to specify a directory for the templates you can do so in koha.conf with 'templatedirectory=younameit'.
34   
35 5. Rules and hints
36  5.1 for the templates
37   -use absolut paths, relative paths in html-tags would be relative to the script's position and relative paths in <TMPL_INCLUDE> would be relative to the template.
38   -you don't have to make templates for everything in your custom-theme or language. if you omit a template in a language the template of next available language is used (languages are tried in the order of the user's browser-settings). 
39    if there is no template in the specified language in a theme a different language will be chosen and NOT a different theme.
40    if you omit a template in all languages the template of the default-theme will be used.
41   -include comments with useful information such as the template's location, this simplifies debugging
42   -use the same name for the template and the script (with different extensions of course)
43  5.2 for the scripts
44   -use meaningfull english (abbreviations) as parameter-names
45   -if you fetch a list of data, pass it completely and let the designer decide which data to use.
46   -working with arrays and loops is always better, even if you have only three similar rows.
47   -don't let the script generate html and pass the output to the template
48   
49 6. Templating stuff in Koha
50   This section is to describe scripts, modules and functions within them to handle with themes, languages and other templating stuff.
51   If you write something which matches this, please add a brief description here (e.g. function calls and return values).
52   -function %path = pathtotemplate(%hash) in C4::Output
53    Takes a hash with the following keys:
54     -template: the name of the template-file (e.g. 'mytemplate.tmpl')
55     -type: 'opac', 'intranet', 'none' or something you specify, decides which directory to lookup, defaults to intranet
56       -'opac': /somedirs/opac-tmpl/theme/language/template.tmpl
57       -'interanet': /somedirs/intranet-tmpl/theme/language/template.tmpl
58       -'none': /somedirs/theme/language/template.tmpl
59       -'my own words': /somedirs/my own words/theme/language/template.tmpl
60       somedirs is 1. the path-parameter if specified 2. the templatedirectory in koha.conf, 3. the includes + '/templates', 4. the includes
61     -theme: you can manually set a theme (e.g. 'customtheme') only if 'allowthemeoverride' in systempreferences is set
62     -language: you can manually set a language (e.g. 'es')
63     -path: you can manually set the path to search for templates (e.g. '/usr/koha/sometesttemplates')
64     You only need to pass the last three parameters if you want to override the preferences for some reasons
65    Returns:
66     - $path{'path'}: the complete+absolute path of the template (e.g. '/somedirs.../opac-tmpl/customtheme/es/mytemplate.tmpl')
67     - $path{'fondlanguage'}: '1' if the requested template was available in the requested language
68     - $path{'fondtheme'}: '1' if the requested template was available in the requested theme
69     
70 7. Links
71   Do you have good links for the templater?
72   The HTML::Template documentation: http://www.perldoc.com/cpan/HTML/Template.html
73   
74   
75 Comments to dnmeid@gmx.de
76 Dorian