Common Header and footer using HTML::Template

Rakish's Avatar, Join Date: Jul 2006
Go4Expert Member
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="">TITLE</a></h1>
	<div id="links">
	<text2 id="text2">Logged in as <TMPL_VAR NAME=USERNAME></text2>
		<a href="">Invite</a> |
		<a href="">Help</a> |
		<a href="">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.

pradeep's Avatar, Join Date: Apr 2005
Team Leader
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;