[htmltmpl] Associate multiple objects/ some should loop
Brought to you by:
samtregar
From: Lists <our...@ro...> - 2003-04-30 19:23:51
|
This is my first project using HTML::Template. I am having difficulty with trying to loop different result sets, each within their own CGI object. I may even be approaching it all wrong; open to suggestions for improvement. It's a membership form - the top section and a few lines at very bottom shows the member's personal info; all values gleaned from CGI object $page which is formed from results of a DBI query to the "member" table. A second DBI query from a second ("business") table populates $biz and $biz2 CGI objects (i.e the member may have more than one business listed). Each fetchrow represents a different business of that same member and becomes a new object. In future, it could conceivably result in 3 or even more $bizX sets of results if we allow the member to list more businesses. The middle part of the template should repeat, showing each business' information ... i.e. --------- Member Name address phone Biz name description contact email for this biz Biz name 2 description contact email for this biz more member specific info --------- I am using associate like this: my $tpl=HTML::Template->new(path=>'/home/domain/www/tpl', filename=>'mypage.tpl', associate=>[$page,$biz,$biz2]); Without using a TMPL_LOOP in the template, that fills in the member info and one iteration of the business info (for the first business listed) just fine. Now how do I get a loop to present at least once (a member will have at least one biz) and then present each optional additional business as well using the params from each subsequent business' CGI object? I know I can do so if I split the biz part of the template out on its own and explicitly/manually make a new call for each business to HTML::Template->new using (if $biz2), (if $biz3), etc... but surely there must be a better way? -------- Jo |