HTML::Template module in perl

Discussion in 'Perl Misc' started by andy, Apr 9, 2007.

  1. andy

    andy Guest

    I have a html file name test.html as below.
    ==================================================================
    <html>
    <head>
    <title>Song Listing</title>
    </head>
    <body>
    <h1>My Songs</h1>

    <tr>

    <td valign="top">
    <table width="150%" border="1" cellpadding="3"
    cellspacing="1">
    <tr height="20" style="font-size: 95%;"><td>&nbsp;</td></tr>

    <tr height="20" style="font-size: 95%;"><td align="left"
    valign="middle"><a href="<TMPL_VAR NAME=SOME_DATA>">NITIN</a></td></
    tr>

    <tr height="20" style="font-size: 95%;"><td align="left"
    valign="middle"><a href="<TMPL_VAR NAME=TEST_THIS_1>">SITE</a></td></
    tr>

    </table>
    </td>

    <table>
    </BODY>
    </HTML>
    ======================================================================
    I am opening this html file using the below perl script.
    ======================================================================
    #!/usr/bin/perl -w
    use strict;
    use CGI;
    use CGI::Session;
    use HTML::Template;
    my $site = "http://www.google.co.in";
    my $FILENAME="/usr/nitin/test_123.tmpl"
    my $cgi = new CGI;
    print $cgi->header();
    my $template = HTML::Template->new(filename => "/usr/nitin/
    test.tmpl");
    #tried with all the below three options: as in the link of SITE of the
    html page i want to open a different template file named
    test_123.tmpl.
    #my $FILENAME= HTML::Template->new(type => 'filename', source => "/usr/
    nitin/test_123.tmpl");
    #my $FILENAME= HTML::Template->new( filename => 'test_123.tmpl', path
    => [ '/usr/nitin/test_123.tmpl']);
    #my $FILENAME= HTML::Template->new_file('test_123.tmpl', filename => '/
    usr/nitin/test_123.tmpl');

    $template->param(SOME_DATA=> $site);
    $template->param(TEST_THIS_1=> $FILENAME);
    print $template->output;
    1;
    =====================================================================

    I am not able to open the test_123.tmpl file by using opening this
    using this method.

    Tried with TMPL_INCLUDE also. But not able to open the same.

    Can anybody help me with the solution.
    ============================================================
    After this I want to first click on NITIN and then on SITE. And then i
    want a new page or template file . i.e after clicking on NITIN and
    then SITE I want to open a new template file. Will it be done by
    TMPL_IF tag under HTML::template module or is there any other way to
    do that.


    Kindly help me with the logic.
     
    andy, Apr 9, 2007
    #1
    1. Advertising

  2. andy wrote:
    > I have a html file name test.html as below.
    > ==================================================================


    <snip>

    So the file is called "test.html"

    > ======================================================================
    > I am opening this html file using the below perl script.
    > ======================================================================
    > #!/usr/bin/perl -w
    > use strict;
    > use CGI;
    > use CGI::Session;
    > use HTML::Template;
    > my $site = "http://www.google.co.in";
    > my $FILENAME="/usr/nitin/test_123.tmpl"
    > my $cgi = new CGI;
    > print $cgi->header();
    > my $template = HTML::Template->new(filename => "/usr/nitin/
    > test.tmpl");


    You're then trying to open it as "test.tmpl".

    > #tried with all the below three options: as in the link of SITE of the
    > html page i want to open a different template file named
    > test_123.tmpl.
    > #my $FILENAME= HTML::Template->new(type => 'filename', source => "/usr/
    > nitin/test_123.tmpl");
    > #my $FILENAME= HTML::Template->new( filename => 'test_123.tmpl', path
    > => [ '/usr/nitin/test_123.tmpl']);
    > #my $FILENAME= HTML::Template->new_file('test_123.tmpl', filename => '/
    > usr/nitin/test_123.tmpl');
    >
    > $template->param(SOME_DATA=> $site);
    > $template->param(TEST_THIS_1=> $FILENAME);
    > print $template->output;
    > 1;


    It's important to check your return values.


    F:\Documents and Settings\Mark3>cat template.pl
    use strict;
    use warnings;

    use HTML::Template;

    my $filename = shift;

    my $template = HTML::Template->new( filename => $filename ) or die $!;

    print $template->output();

    F:\Documents and Settings\Mark3>perl template.pl notexists.tmpl
    HTML::Template->new() : Cannot open included file notexists.tmpl : file
    not found. at F:/Perl/site/lib/HTML/Template.pm line 1658

    HTML::Template::_init_template('HTML::Template=HASH(0x18c249c)') called
    at F:/Perl/site/lib/HTML/Template.pm line 1238
    HTML::Template::_init('HTML::Template=HASH(0x18c249c)') called
    at F:/Perl/site/lib/HTML/Template.pm line 1124
    HTML::Template::new('HTML::Template', 'filename',
    'notexists.tmpl') called at template.pl line 8

    F:\Documents and Settings\Mark3>echo test template > exists.tmpl

    F:\Documents and Settings\Mark3>perl template.pl exists.tmpl
    test template
     
    Mark Clements, Apr 9, 2007
    #2
    1. Advertising

  3. andy

    J. Gleixner Guest

    andy wrote:
    [...]
    > #my $FILENAME= HTML::Template->new(type => 'filename', source => "/usr/
    > nitin/test_123.tmpl");
    > #my $FILENAME= HTML::Template->new( filename => 'test_123.tmpl', path
    > => [ '/usr/nitin/test_123.tmpl']);
    > #my $FILENAME= HTML::Template->new_file('test_123.tmpl', filename => '/
    > usr/nitin/test_123.tmpl');
    >
    > $template->param(SOME_DATA=> $site);
    > $template->param(TEST_THIS_1=> $FILENAME);
    > print $template->output;
    > 1;
    > =====================================================================
    >
    > I am not able to open the test_123.tmpl file by using opening this
    > using this method.


    perldoc -f open

    >
    > Tried with TMPL_INCLUDE also. But not able to open the same.
    >
    > Can anybody help me with the solution.
    > ============================================================
    > After this I want to first click on NITIN and then on SITE. And then i
    > want a new page or template file . i.e after clicking on NITIN and
    > then SITE I want to open a new template file. Will it be done by
    > TMPL_IF tag under HTML::template module or is there any other way to
    > do that.


    You have to 'open' a file for write. TMPL_INCLUDE will insert the
    contents of a pre-existing file.

    >
    >
    > Kindly help me with the logic.


    Use HTML::Template to populate predefined values in a file/template.
    Use an editor, or 'open' a file in your CGI, or other methods to
    create a file.
     
    J. Gleixner, Apr 9, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Theis
    Replies:
    2
    Views:
    493
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    556
    tom_usenet
    Jul 24, 2003
  3. ChrisO
    Replies:
    8
    Views:
    169
    ChrisO
    Sep 15, 2004
  4. C. Olive
    Replies:
    1
    Views:
    270
    Chris Smith
    Oct 4, 2003
  5. andy

    HTML::template Module in perl

    andy, Apr 6, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    143
Loading...

Share This Page