Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Web page template for an HTTP daemon script

by benn (Priest)
on Aug 13, 2003 at 12:04 UTC ( #283515=note: print w/ replies, xml ) Need Help??


in reply to Web page template for an HTTP daemon script

Try HTML::Template or the Template Toolkit - these should suit your needs.

Cheers
Ben.


Comment on Re: Web page template for an HTTP daemon script
Replies are listed 'Best First'.
Re: Re: Web page template for an HTTP daemon script
by bronto (Priest) on Aug 13, 2003 at 13:11 UTC

    Definitely not. I am not using Apache, nor I am using CGIs: my web server is the script itself. I need a template, an HTML mixed with perl variables, that I could evaluate each time the show_form subroutine is called.

    Anyway, thanks for trying.

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz
      Ermmm - you don't need Apache or CGI to use either of the modules I mentioned - the Template Toolkit particularily is designed for / used in all sorts of applications, most of which are nothing to do with CGI.

      From the 'Template' synopsis...

      my $vars = { var1 => $value, var2 => \%hash, var3 => \@list, var4 => \&code, var5 => $object, }; my $input = 'myfile.html'; $template->process($input, $vars) || die $template->error();

      Cheers, Ben.

        Put the blame on Sam Tregar, then :-)
        as you can see, HTML::Template docs say:

        HTML::Template - Perl module to use HTML Templates from CGI scripts

        Ok, ok; next time I'll continue to read the documents after the NAME section :-)

        Ciao!
        --bronto


        The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
        --John M. Dlugosz
      In your code:
      sub show_form { my $c = shift ; my $status = status() ; my $message = get_message() ; my $service_name = '' # where do you get this from?!? my $template = HTML::Template->new(filename => 'form.tmpl'); $template->param( service_name => $service_name, status => $status, message => $message, ); reset_message; # shouldn't you use parens here? my $resp = HTTP::Response->new ; $resp->content($template->output) ; $c->send_response($resp) ; }
      And the template:
      <html> <head> <title><tmpl_var service_name> controls</title> </head> <body> <h1 align="center"><tmpl_var service_name> controls</h1> <div align="center"> <table style="border-width: 2px ; border-style: solid"> <tr align="center"> <td> <form action="/start" method="post"> <input type="submit" value=" Start " > </form> </td> <td> <form action="/stop" method="post"> <input type="submit" value=" Stop " > </form> </td> <td> <form action="/restart" method="post"> <input type="submit" value=" Restart " > </form> </td> </tr> <tr align="center"> <td colspan="3"> <form action="/status" method="post"> <input type="submit" value=" Update status " > </form> </td> <tr> <tr> <td colspan="3" align="center"><tmpl_var message></td> <tr> <tr> <td colspan="3">Status: <tmpl_var service_name> is <tmpl_var + status></td> <tr> </table> </div> </body> </html>

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
      As benn pointed out, those work in any Perl script, not just in CGI. If you don't like them for other reasons, look ay Text::Template for a simple approach to templates.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2015-07-28 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (257 votes), past polls