SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I'm not a human
    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();
    and the template file content is,
    Code:
    <center>
    <body>
    	<table align=center border=0 style="border:1px solid blue;" width=60&#37;>
    	<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>
    this is not working and rendering the following error
    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
    But look at the following code it's working properly and i couldn't find much difference between the two.. s
    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();
    and the template file content is,
    Code:
    <body><center>
    Today is <TMPL_LOOP NAME=EMPLOYEE_INFO>
          Name: <TMPL_VAR NAME=NAME> <br>
          Job:  <TMPL_VAR NAME=JOB>  <p>
       </TMPL_LOOP>
    the above code is working nicely...


    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..
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    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();
    change the line to:

    $template->param(top_sender=>\@top);

    that will now send a reference to @top instead of the array @top. Hopefully thats all it is.

  3. #3
    I'm not a human
    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.
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  4. #4
    SitePoint Wizard bronze trophy KevinR's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •