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:

Code:
<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>
	</div>
</div
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's Avatar, Join Date: Apr 2005
Team Leader
Here is an example:

The template file:
HTML Code:
<html>
 <head><title>Test Template</title></head>
  <body>
  <h3>My Header
  
  <TMPL_LOOP NAME=LP>
  <font color=green>Name :  
  
  Dept : <TMPL_VAR NAME=DEPT> 
  
  </TMPL_LOOP>
  <br/>
  <center>This is my footer
  </body>
  </html>
The Perl file:
Code: Perl
#!/usr/bin/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'};
 
  $template->param(LP=>\@loop_data);
 
  print $q->header,$template->output;