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.cgi
#!/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++; }
gallery.tpl
<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)

Just Another Perl Alchemist

In reply to How to Seperate Presentation from Implementation with HTML::Template by Koosemose

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.