Koosemose has asked for the wisdom of the Perl Monks concerning the following question:
I've made a rather simplistic Image Gallery script for a web site I've recently begun to help with, using HTML::Template. However I have now come to a problem. In a particular spot I can't seem to unmix some design and presentation.
The only way I can figure out how to set the number of images per row is with a counter of the number of images found mod the number of images I want per row. However, number of images per row is definitely a presentation element, and I would like the fellow who is in charge of the site design to be able to alter the images per row. I could make use of HTML::Template::Expr, so that I can have the mod bit take place in the template and the web monkey would have access to the images per row, but that would have a potentially confusing bit of implementation in the presentation. Can anyone present any ideas for clearer seperation of implementation and design?
For reference, the code and template follow:
gallery.cgigallery.tpl#!/usr/bin/perl use warnings; use strict; use File::Find; use HTML::Template; my $template = HTML::Template->new(filename => 'gallery.tpl'); my @thumbnails; my $count = 1; my %options = (wanted=>\&pics , no_chdir=>1); find(\%options, 'thumbs/'); $template->param(THUMBNAIL => [ @thumbnails ] ); print "Content-Type: text/html\n\n", $template->output; sub pics { return unless /\.((?:jpg)|(?:gif)|(?:png)$)/i; my $thumbfile = "$_"; my $imagefile = "$_"; $imagefile =~ s/thumbs/images/; push @thumbnails,{image=>$imagefile, thumb=>$thumbfile, newrow=>$count%5}; ##This is the imporant bit $count++; }
<html> <title>Image Gallery</title> <body> <table colspan=5 align=center border=1> <tr> <TMPL_LOOPTHUMBNAIL> <td border=0><a href='<TMPL_VAR IMAGE>'><img src='<TMPL_VAR THUM +B>'></a></td> <TMPL_UNLESS __last__><TMPL_UNLESS newrow></tr><tr></TMPL_UNLES +S></TMPL_UNLESS> </TMPL_LOOP> </tr> </table </body> </html>
There's also a seperate backend which actually creates the thumbnails, but I didn't think it was relavent, if you think it may be, then let me know and I'll include that also
And on an entirely unrelated note, today is my 3rd monkday, and this is my first question and root post. (Yes I've went that long and never asked a question, at least not in a post, lots of 'em in the CB)
|
|---|