Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to use HTML::Template with just source code? such as this:
my $sth = $dbh->prepare(qq{select * from `sometable` where `id` = ?}); $sth->execute($some_string); my $data = $sth->fetchrow_hashref(); $sth->finish(); my $page_title = $data->{title}; my $html_content = $data->{html_src}; my $last_edited = Format_Date_For_Viewing($data->{last_modified},"long +_date"); # Use the HTML Content in $html_content with the HTML::Template??
Thanks

Replies are listed 'Best First'.
Re: Use of HTML::Template
by GrandFather (Saint) on Feb 08, 2009 at 08:40 UTC

    The second example in the HTML::Template documentation given for the new method is:

    my $t = HTML::Template->new( scalarref => $ref_to_template_text, option => 'value' );

    which seems to cover your use case.


    Perl's payment curve coincides with its learning curve.
      Thank you...

      One more quick question, what is this: (I'll put a comment in front of the code I have a question about...
      my $t = HTML::Template->new( scalarref => $ref_to_template_text, # option => 'value' );
      I don't understand the option and what it is for.

      Thanks

        A place holder for any of the optional parameters to the new method. Sorta like saying ...->new (foo => 'bar', boo => 'baz', ...). The 'scalerref' option is the interesting one and you can remove the commented line without any nasty surprises.


        Perl's payment curve coincides with its learning curve.