[Koha-devel] Templating design

Finlay Thompson finlay at katipo.co.nz
Tue Oct 1 14:35:25 CEST 2002


Hi Everyone,

It seems that everyone had a email conversation about the way templating
is being done in koha. I have been working on templating the opac. Let
me explain what I have done, which is not to say that it is the right
way :-)

Firstly I should point out that I have been developing on the rel-1-2
branch, but will probably merge this into the 1.3 release.

If you want to go and check it out go to http://opacdev.katipo.co.nz

you can login using user:pword = frank:frank or finlay:finlay


CVS: All the templates are going into the koha-tmpl tree of cvs. 

under this root we have two sub-branches intranet-tmpl/ and opac-tmpl/

eveything onder there should be installed in koha/intra/htdocs/ and
koha/opac/htdocs/ respectivly.

And then we have the structure: <theme>/<lang>/<scriptname>.tmpl

I suggest that we try hard to keep the templates and scripts with the
same names.....

includes and images go under the <theme>/<lang>/ directory.....

An example:
The opac-search.pl script presents the search form in the opac.
see: http://opacdev.katipo.co.nz/cgi-bin/koha/opac-search.pl

it calls the opac-search.tmpl template which in this instance is found
in the default/en/ theme and language.

There is an include at the top: cat-top.inc and this is found in
default/en/includes/cat-top.inc all the images in the templates are
prefixed by the HTML::Template tag: <TMPL_VAR NAME="themelang">
eg. src="<TMPL_VAR NAME='themelang'>/images/search-button.gif"
This template variable is automatically passed to includes and is
automatically loaded into the template by the template loading
subroutine.....

Template loading:
The relevant code in opac-search.pl is:

	use C$::Output;
	my $template = gettemplate("opac-search.tmpl", "opac");

The method gettemplate handles eveything about choosing theme and lang
settings and finding a template etc. It then loads the "themelang"
variable and returns the template. The "opac" string is simply to switch
to the opac tree. however in the future this gettemplate method could
perhaps be made to take a hash of options? 


Note: there is another candidate for the gettemplate code that Dorian
wrote. His subroutine is called "pathtotemplate" and does many of the
same things, except it doesnt actually intialise the template.

I think that keeping the template intialising code to one line is a good
idea, and I dont think there is any loss of flexibility if I allow
gettemplate to pass a hash of options to the HTML::Template module.

I like what andrew said with regard to something else the other day:

	"This way, simple scripts remain simple, and complex scripts 	become
possible."

That is a very good principle. As most of the time the scripts have one
template associated, and no extra options on the template, the above
one-liner will be enough.



Anyway, I hope this has clarified what I have been up to.

I will update the reading material on:
http://koha.org/contribute/templating/

Finlay










More information about the Koha-devel mailing list