The basic process is that rss reads the config file
(lastAcquired.conf) to determine RSS header information, the SQL query
-used to generate the results, and the HTML::Template style used to
+used to generate the results, and the Template Tookit style used to
format the output. Since you'll likely to want to create your own RSS
content, or at least modify the ones present here, let's review the
config file and the template file.
url=http://www.koha-community.org/images/foo.jpg
link=http://www.koha-community.org
config
-tmpl=lastAcquired.tmpl
+tmpl=lastAcquired.tt
output=lastAcquired.xml
query=select biblioitems.isbn as isbn, biblio.title as title, biblio.author as author from biblio, biblioitems, items where biblioitems.biblionumber = items.biblionumber and biblio.biblionumber = items.biblionumber and items.dateaccessioned is not NULL order by items.dateaccessioned desc
This data (and the data acquired from the query) are then used to fill
in the template. Most of the template is boilerplate and should not
-be edited. The section within the <TMPL_LOOP NAME=ITEMS>
-... </TMPL_LOOP> is the part which can be modified to create your own
-RSS content.
+be edited. The section within the [% FOREACH i IN ITEMS %] ... [% END %]
+is the part which can be modified to create your own RSS content.
Here's the lastAcquired.tmpl file:
<rss version="0.91">
<channel>
- <title><TMPL_VAR CHANNELTITLE></title>
- <link><TMPL_VAR CHANNELLINK></link>
- <description><TMPL_VAR CHANNELDESC></description>
- <language><TMPL_VAR CHANNELLANG></language>
- <lastBuildDate><TMPL_VAR CHANNELLASTBUILD></lastBuildDate>
+ <title>[% CHANNELTITLE %]</title>
+ <link>[% CHANNELLINK %]</link>
+ <description>[% CHANNELDESC %]</description>
+ <language>[% CHANNELLANG %]</language>
+ <lastBuildDate>[% CHANNELLASTBUILD %]</lastBuildDate>
<image>
- <title><TMPL_VAR IMAGETITLE></title>
- <url><TMPL_VAR IMAGEURL></url>
- <link><TMPL_VAR IMAGELINK></link>
+ <title>[% IMAGETITLE %]</title>
+ <url>[% IMAGEURL %]</url>
+ <link>[% IMAGELINK %]</link>
</image>
-<TMPL_LOOP NAME=ITEMS>
+[% FOREACH i IN ITEMS %]
<item>
- <title><TMPL_VAR TITLE>, by <TMPL_VAR AUTHOR></title>
- <link>http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn=<TMPL_VAR ISBN></link>
-
+ <title>[% i.TITLE %], by [% i.AUTHOR %]</title>
+ <link>http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn=[% i.ISBN %]</link>
</item>
-</TMPL_LOOP>
+[% END %]
</channel>
</rss>
advice, and help came from 'Content Syndication with RSS', Chris
Cormack, Mike Hansen, Steve Tonnesen and a variety of folks on #koha at
irc.katipo.co.nz.
+Updated for use with Template Toolkit by Kyle M Hall, ByWater Solutions
#
# Copyright 2003 Katipo Communications
+# Copyright 2014 ByWater Solutions
#
# This file is part of Koha.
#
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-use strict;
-use warnings;
+use Modern::Perl;
-use HTML::Template::Pro;
+use Template;
use C4::Context;
use Time::Local;
use POSIX;
my $file = $ARGV[0];
my %config = getConf("config");
my $outFile = $config{"output"};
-my $feed = HTML::Template::Pro->new( filename => $config{"tmpl"} );
+my $feed = Template->new();
my %channel = getConf("channel");
-$feed->param( CHANNELTITLE => $channel{'title'} );
-$feed->param( CHANNELLINK => $channel{'link'} );
-$feed->param( CHANNELDESC => $channel{'desc'} );
-$feed->param( CHANNELLANG => $channel{'lang'} );
-$feed->param( CHANNELLASTBUILD => getDate() );
+my %image = getConf("image");
+my $vars = {
+ CHANNELTITLE => $channel{'title'},
+ CHANNELLINK => $channel{'link'},
+ CHANNELDESC => $channel{'desc'},
+ CHANNELLANG => $channel{'lang'},
+ CHANNELLASTBUILD => getDate(),
-my %image = getConf("image");
-$feed->param( IMAGETITLE => $image{'title'} );
-$feed->param( IMAGEURL => $image{'url'} );
-$feed->param( IMAGELINK => $image{'link'} );
-$feed->param( IMAGEDESCRIPTION => $image{'description'} );
-$feed->param( IMAGEWIDTH => $image{'width'} );
-$feed->param( IMAGEHEIGHT => $image{'height'} );
+ IMAGETITLE => $image{'title'},
+ IMAGEURL => $image{'url'},
+ IMAGELINK => $image{'link'},
+ IMAGEDESCRIPTION => $image{'description'},
+ IMAGEWIDTH => $image{'width'},
+ IMAGEHEIGHT => $image{'height'},
-#
-# handle the items
-#
-$feed->param( ITEMS => getItems( $config{'query'} ) );
+ ITEMS => getItems( $config{'query'} )
+};
-open( FILE, ">$outFile" ) or die "can't open $outFile";
-print FILE $feed->output();
-close FILE;
+my $template_path = $config{"tmpl"};
+open( my $fh, "<", $template_path ) or die "cannot open $template_path : $!";
+$feed->process( $fh, $vars, $outFile );
sub getDate {
-
- # my $date = localtime(timelocal(localtime));
my $date = strftime( "%a, %d %b %Y %T %Z", localtime );
return $date;
}
my @line = split( /=/, $_, 2 );
unless ( $line[1] ) {
$inSection = 0;
- } else {
+ }
+ else {
my ( $key, $value ) = @line;
chomp $value;
$return{$key} = $value;
}
- } else {
+ }
+ else {
if ( $_ eq "$section\n" ) { $inSection = 1 }
}
}