SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Dec 25, 2008, 23:18 #1
- Join Date
- Aug 2006
- Location
- India
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
HTML::Template : Attempt to set nonexistent parameter 'top_sender'
hi,
I've been using the HTML:Template for the page design in Perl.
but the stuff works for some time and not working for some time..
I couldn't find the problem,
Look at my code,Code:#!d:/perl/bin/perl use HTML::Template; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; my @top = ( {namee=>'raju',job=> '3434'}, {namee=>'ramesh',job=> '234'}, {namee=>'rajesh',job=> '123'}, ); my $template = HTML::Template->new(filename => 'index.tmpl'); $template->param(top_sender=>@top); print "Content-Type: text/html\n\n", $template->output();
Code:<center> <body> <table align=center border=0 style="border:1px solid blue;" width=60%> <th colspan=2>Top 10 Senders</th> <tr><td>Sender</td><td>Count</td></tr> <tr> <tmpl_loop name="top_sender"> <td> Name: <tmpl_var name="namee"></td> <td>Job:<tmpl_var name="job"></td> </tmpl_loop> </tr> </table></body></center> </html>
HTML::Template : Attempt to set nonexistent parameter 'top_sender' - this parameter name doesn't match any declarations in the template file : (die_on_bad_params => 1) at e:\LOGANA~1\html\sample.pl line 20
Code:#!d:/perl/bin/perl -T use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; warningsToBrowser(1); # this should be put after printing the header; use CGI qw(:all); use HTML::Template; use POSIX; print header; print "Content-type: text/html\n\n"; my $template = HTML::Template->new(filename => 'sample.tmpl'); $template->param(EMPLOYEE_INFO => [{ name => 'Sam', job => 'programmer' }, { name => 'Steve', job => 'soda jerk dfds' },] ); print $template->output();
Code:<body><center> Today is <TMPL_LOOP NAME=EMPLOYEE_INFO> Name: <TMPL_VAR NAME=NAME> <br> Job: <TMPL_VAR NAME=JOB> <p> </TMPL_LOOP>
Something awkward..
Some time ago i tried to print the html content using print and the code rendered some error and when i added an empty line after last code it worked... seems the perl is something complicated than other programming languages..
-
Dec 26, 2008, 09:42 #2
- Join Date
- Nov 2004
- Location
- Moon Base Alpha
- Posts
- 1,053
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Its been a while since I used that module, but I think the problem is you are not sending a reference to your array of hashes:
Code:#!d:/perl/bin/perl use HTML::Template; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; my @top = ( {namee=>'raju',job=> '3434'}, {namee=>'ramesh',job=> '234'}, {namee=>'rajesh',job=> '123'}, ); my $template = HTML::Template->new(filename => 'index.tmpl'); $template->param(top_sender=>@top);##<--- HERE IS THE PROBLEM print "Content-Type: text/html\n\n", $template->output();
$template->param(top_sender=>\@top);
that will now send a reference to @top instead of the array @top. Hopefully thats all it is.
-
Feb 9, 2009, 23:57 #3
- Join Date
- Aug 2006
- Location
- India
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can Anyone recommend me a perl module or technique to integrate HTML with Perl.
I'm using HTML::Template but it is causing some problems.
I want to know what is the latest technique used to integrate HTML with perl.
-
Feb 10, 2009, 03:11 #4
- Join Date
- Nov 2004
- Location
- Moon Base Alpha
- Posts
- 1,053
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Look into Mason:
http://www.masonbook.com/
Bookmarks