in reply to Re: Web page template for an HTTP daemon script
in thread Web page template for an HTTP daemon script

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Re: Re: Web page template for an HTTP daemon script
by benn (Vicar) on Aug 13, 2003 at 13:30 UTC
    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
3Re: Web page template for an HTTP daemon script
by jeffa (Bishop) on Aug 13, 2003 at 14:07 UTC
    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)
    
Re: Re: Re: Web page template for an HTTP daemon script
by perrin (Chancellor) on Aug 13, 2003 at 13:43 UTC
    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.