Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: HTML::Template help

by dragonchild (Archbishop)
on Apr 22, 2005 at 15:05 UTC ( #450443=note: print w/ replies, xml ) Need Help??


in reply to HTML::Template help

  1. You have been told on repeated occasions to use strict; and use warnings;. I won't review any code of yours longer than 5 lines that doesn't have those at the top.
  2. Start small - create a small script that uses a small template, without Javascript or Unicode. Learn the tool, then apply it. You're going backwards.
  3. If you have a problem, you should remove pieces from the problemspace until you have the smallest example that demonstrates the problem. If you remove a piece and the problem goes away, the problem is related to the piece you removed.
  4. Have you compared the HTML you generated with your old code against the HTML you're generating with the new code? Do you still have your old code? (You are using some sort of source control management like CVS or Subversion, right?)
  5. Have you tried to run this script from the command-line? CGI has a command-line mode that's kinda handy.

Start with that. If those steps don't fix the problem, come back and ask questions then.


Comment on Re: HTML::Template help
Select or Download Code
Re^2: HTML::Template help
by Nik on Apr 22, 2005 at 15:17 UTC
    For example in my cgi.pm vesrsion i was loading the value in a drop down menu. here i try to dot he same in my tamplate file but i cant. i cant evne print a value
    <TMPL_LOOP name=@files> <option value="<TMPL_VAR name=@files>"><TMPL_VAR name=@files></option> </TMPL_LOOP>
    here is the perl code that tries to fill in those values:
    @display_files = map ( /([^\/]+)\.txt/, glob '../data/text/*.txt' ); @files = map { option => $_ }, @display_files; $tmpl->param( options => \@files );
    Why doesnt it fill the values in the drop down menu?
      It doesn't look like you actually read the HTML::Template documentation. If you had, you would have read the section on TMPL_LOOP.

      Try a smaller template. You need to learn the tool before you convert your big project to it.

        i just did and i still cant see work this out.
      The names of the TMPL_* variables must match the keys of the hash you use in HTML::Template's param method.

      For example, if you have a TMPL_VAR named "foo", then you must do $tmpl->param(foo => "bar") to fill in that TMPL_VAR in the template with the value "bar".

      The structure of your data is right (you pass an array of hashes for a TMPL_LOOP), but the names of the hash keys don't match the names in the template. Since you write $tmpl->param(options => \@files), the TMPL_LOOP must be named "options" (not "@files"). Then, since each of the hashrefs in @files has a key called "option", the TMPL_VAR within the TMPL_LOOP must be named "option"

      To recap, change the names in your template to match the names of the hash keys you use in param():

      <TMPL_LOOP name=options> <option value="<TMPL_VAR name=option>"><TMPL_VAR name=option></option> </TMPL_LOOP>

      blokhead

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://450443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (16)
As of 2014-07-14 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (268 votes), past polls