7 # Copyright 2009 Chris Cormack and The Koha Dev Team
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
26 Koha::Templates - Object for manipulating templates for use with Koha
30 use base qw(Class::Accessor);
32 use Template::Constants qw( :debug );
36 __PACKAGE__->mk_accessors(qw( theme lang filename htdocs interface vars));
40 my $interface = shift;
43 if ( $interface ne "intranet" ) {
44 $htdocs = C4::Context->config('opachtdocs');
47 $htdocs = C4::Context->config('intrahtdocs');
50 # my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
53 my $template = Template->new(
57 INCLUDE_PATH => "$htdocs/$theme/$lang/includes",
61 ) or die Template->error();
63 TEMPLATE => $template,
69 $self->filename($filename);
70 $self->htdocs($htdocs);
71 $self->interface($interface);
72 $self->{VARS}->{"test"} = "value";
80 # my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename;
81 my $template = $self->{TEMPLATE};
82 if ($self->interface eq 'intranet'){
83 $vars->{themelang} = '/intranet-tmpl';
86 $vars->{themelang} = '/opac-tmpl';
88 $vars->{lang} = $self->lang;
89 $vars->{themelang} .= '/' . $self->theme . '/' . $self->lang;
90 $vars->{yuipath} = (C4::Context->preference("yuipath") eq "local"?$self->{themelang}."/lib/yui":C4::Context->preference("yuipath"));
91 $vars->{interface} = ( $vars->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' );
92 $vars->{theme} = $self->theme;
93 $vars->{opaccolorstylesheet} = C4::Context->preference('opaccolorstylesheet');
94 $vars->{opacsmallimage} = C4::Context->preference('opacsmallimage');
95 $vars->{opacstylesheet} = C4::Context->preference('opacstylesheet');
96 #add variables set via param to $vars for processing
97 for my $k(keys %{$self->{VARS}}){
98 $vars->{$k} = $self->{VARS}->{$k};
101 $template->process( $self->filename, $vars, \$data) || die "Template process failed: ", $template->error();;
105 # wrapper method to allow easier transition from HTML template pro to Template Toolkit
111 utf8::encode($val) if utf8::is_utf8($val);
112 if( ref($val) eq 'ARRAY' && ! scalar @$val ){ $val = undef; }
113 elsif( ref($val) eq 'HASH' && ! scalar %$val ){ $val = undef; }
114 $self->{VARS}->{$key} = $val;