Hello everyone

I have recently incorporated Class::DBI into my CGI::Application (whichi is wicked cool just incase anyone had any doubts) and I wanted to exploite it a little more. My problem is that I use HTML::Template and right now don't want to swtich to Template::Toolkit. I found the plugin for HTML::Template that allows for Dot magick and that seems to help me for simple things.

But for the life of me I cannot figure out how to use simple loops. For instance this works:

# In perl script my $article = MPDatabase::Article->retrieve($articleId); $template->param(article => $article); return $template->output; # In the template file <!-- TMPL_VAR NAME="article.title" --> <!-- TMPL_VAR NAME="article.author" --> etc...

But this does not:

# In perl script my @articles = MPDatabase::Article->retrieve_all; $template->param(article_loop => \@articles); return $template->output; # In the template file <!-- TMPL_LOOP NAME="article_loop" --> <!-- TMPL_VAR NAME="this.title" --> <!-- TMPL_VAR NAME="this.author" --> etc... <!-- /TMPL_LOOP -->

By looking at the example the docs give I would assume I could do this. In the docs they only give an example where the array is an element of the variable they pass in. They do not show how to do it if you are passing in the array directly. Can I just not do this? Thanks

!!UPDATE!!

Okay so I sorta figured it out. If I do this:

foreach my $article ( @articles ) { print STDERR $article->anyColumnName; }

before I populate the template params it works. I think this has to do with the lazy loading thing of Class::DBI? Now what to do about it.... hrm...


In reply to Using loops with HTML::Template::Dot by debiandude

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.