My problem though, is that I'd like to only show the top 'n' most-recent articles, not all of them. I have the articles in a file, templates/articles.tmpl, which contains the an article header (example below). In the header is a link to the full article, which is in it's own template as well.
Article Header example:
(some of the HTML tags may look disjointed, but they do match, since this is encapsulated in a larger piece of HTML)<br /> <TMPL_VAR NAME=ARTICLE_HDR_FRAME> <tr> <td><TMPL_VAR NAME=ARTICLE_HDR_BODY> <tr> <td align="left"> <img src="<TMPL_VAR NAME=IMAGES>/new_package.gif" alt="09- +22-2001" width="12" height="12" border="0" /> <a href="<TMPL_VAR NAME=SCRIPT>/article015"><TMPL_VAR NAME +=FONTFACE><font color="blue"><b>My Article Title</b></font></a> </td> <td align="right"><i>Saturday, September 22nd, 2001</i></td> </tr> </table> </td> </tr> </table> <table cellspacing="0" cellpadding="1" border="0" bgcolor="#ffffff" wi +dth="100%"> <tr> <td><TMPL_VAR NAME=FONTFACE>A small blurb of the article, a 'tea +ser', which is the first few sentences of the full article.</font></t +d> </tr> </table>
My code for loading articles.tmpl looks like this:
I can't seem to figure out a way, without reading in the file with 'open(ART, "templates/articles.tmpl") or dir "Foo!" {...}' and then splitting at the 'nth' blank line between article constructs, to limit the front page to display the top 5 most recent articles, for example. When the user clicks on the 'All Articles' link, the full article list will be shown, from 0..n.sub front_page_articles { my $fp_article_template = HTML::Template->new(filename => 'templates/a +rticles.tmpl'); $fp_article_template->param( ARTICLE_HDR_FRAME => $article_hdr_frame, ARTICLE_HDR_BODY => $article_hdr_body, IMAGES => $images, FONTFACE => "$fontface", SCRIPT => $script, SITE => $site, ); print $fp_article_template->output; }
How can I do this? Am I using the wrong tool?
Edit ar0n -- fixed title
In reply to HTML::Template 'splicing' help by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |