#!/usr/bin/perl

# import module
use dTemplate;

# set base dir for templates
$templateDir = "../htdocs/templates";

# set up a list of templates to be used
%templates = ("header" => "header.tmpl", "footer" => "footer.tmpl", "body"
=> "body.tmpl");

# create a dTemplate object for each template $templates={}; foreach $name (keys(%templates)) {
        $templateName = $templateDir . "/" . $templates{$name};
        $templates->{$name} = dTemplate->new(file => $templateName); }

# parse templates and replace variables
# append the result of each parse() to previous call $output = $templates->{header}->parse(TITLE => "Successful login"); $output .= $templates->{body}->parse(USERNAME => "tim", UNREAD => 19, SPAM => 12); $output .= $templates->{footer}->parse();

# print rendered version
print "Content-Type: text/html\n\n";
print $output;