Good afternoon fellow monks. Today's problem is with HTML::Template. I have a website which is driven primarily by HTML::Template, and on the front page of the website is a small row of recent articles. Each article's title/date/author are bordered in a small table, and the first few lines of the article are shown below it. Clicking on the title will bring you to a full page of the full article content. This part works.

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:

<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" />&nbsp; <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>
(some of the HTML tags may look disjointed, but they do match, since this is encapsulated in a larger piece of HTML)

My code for loading articles.tmpl looks like this:

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; }
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.

How can I do this? Am I using the wrong tool?

Edit ar0n -- fixed title


In reply to HTML::Template 'splicing' help by hacker

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.