Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Common Header and footer using HTML::Template (http://www.go4expert.com/forums/common-header-footer-using-htmltemplate-t2771/)

Rakish 30Jan2007 23:41

Common Header and footer using HTML::Template
Hello all,

I am using HTML::Template to separate the design from logic. As of now I am using html header and footer in all template pages as under:


<div id="header">

<h1><a id="bigtext" title="Go to home page" href="home.pl">TITLE</a></h1>
        <div id="links">
        <text2 id="text2">Logged in as <TMPL_VAR NAME=USERNAME></text2>
                <a href="get_email.pl">Invite</a> |
                <a href="help.pl">Help</a> |
                <a href="logout.pl">Logout</a>

but I want to have this code in one file and want to include that file in all the pages.

Any suggestions will be appreciated.

Rakish :)

pradeep 2Feb2007 11:22

Re: Common Header and footer using HTML::Template
Here is an example:

The template file:
HTML Code:

 <head><title>Test Template</title></head>
  <h3>My Header
  <font color=green>Name : 
  <center>This is my footer

The Perl file:
Code: Perl

  use CGI;
  use CGI::Carp /warningsToBrowser fatalsToBrowser/;
  use HTML::Template::Compiled compatible => 1;
  use DBI;
  $q = new CGI;
  my $template = HTML::Template::Compiled->new(filename => 'tpl/test.tpl', die_on_bad_params => 0);
  @loop_data = ();
  $loop_data[0] = {'EMP_NAME'=>'Pradeep','DEPT'=>'Programming'};
  $loop_data[1] = {'EMP_NAME'=>'Manindar','DEPT'=>'Accounts'};
  $loop_data[2] = {'EMP_NAME'=>'Asha','DEPT'=>'Marketing'};
  $loop_data[3] = {'EMP_NAME'=>'Tanaz','DEPT'=>'Programming'};
  print $q->header,$template->output;

All times are GMT +5.5. The time now is 20:45.