debiandude has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Tempate::Dot
by rhesa (Vicar) on Jun 09, 2006 at 11:46 UTC | |
by debiandude (Scribe) on Jun 09, 2006 at 12:03 UTC | |
|
Re: Using loops with HTML::Template::Dot
by strat (Canon) on Jun 10, 2006 at 10:39 UTC |