Hi Monks!
I am trying to get some understanding on this script using CGI::Application but using
a different template system them HTML::Template. I am trying to use Template::Simple. I can't
figure it out how would the changes be, if someone here has or had any previous work
on this kind of thing and would like to tell me how I can do this, it would be very nice!
Here is some sample code I am trying with:
# Hello.pm package Hello; use lib qw(.); use base 'CGI::Application'; use lib '../lib' ; use Template::Simple; use strict; # Run at startup sub setup { my $self = shift; $self->start_mode('mode1'); $self->run_modes( 'mode1' => 'helloworld_sub', ); # Use current path as template path, # i.e. the template is in the same directory as this script #$self->tmpl_path('./'); $self->Template::Simple->new( search_dirs => [ ('./') ], ); } # Usgin Template Simple sub helloworld_sub { # The application object my $self = shift; # The message my $that_famous_string = 'Hello, there World!'; # Open the html template # NOTE 1: load_tmpl() is a CGI::Application method, not a HTML::Te +mplate method. # NOTE 2: Setting the 'cache' flag caches the template if used wit +h mod_perl. #my $template = $self->load_tmpl( # 'hello.tmpl', # cache => 1, # ); # Fill in some parameters #$template->param( # THAT_FAMOUS_STRING => $that_famous_string, # ); # Parse the template #my $html_output = $template->output; ## Using Template Simple my $display_vars; $display_vars->{'famous'} = $that_famous_string; $self->compile( 'hello'); my $html_output = $self->render( 'hello', $display_vars ); #print $$html_output; return $html_output; } 1;

this is the template code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title>[% famous %]</title> </head> <body> <h3>Frame Test</h3></b> <b>[% famous %]</b> </body> </html>

The caller code:
#!/usr/bin/perl -wT ## ## CGI Application Hello World ## use strict; use lib qw(.); use Hello; my $helloworld = Hello->new(); $helloworld->run();

Thanks for looking!

In reply to Template simple with CGI::Application by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.