<?php
/* $Id: phplibtemplate_example.php,v 1.3 2000/07/16 20:04:34 jesus Exp $ */
include("./phplib_template.inc");
include("./class.PHPLIBTemplateAdaptor.php");
include("./class.CachedTemplate.php");
// create Template instance called $ptpl
$ptpl = new CachedTemplate();
$start = $ptpl->utime();
$ptpl->init(".", "keep");
// define variables named page and box, referencing files
$ptpl->set_file(array(
"page" => "ptpl_page.ihtml",
"box" => "ptpl_box.ihtml"));
// Check if we can send the cached file
if ($ptpl->valid_cache_file()) {
echo "<B>FROM CACHE</B>\n<BR>";
$ptpl->read_from_cache();
$end = $ptpl->utime();
$runtime = ($end - $start) * 1000;
echo "<br>Completed in $runtime miliseconds<BR>\n";
exit;
}
// Otherwise process the page
// extract the block named "row" from "box", creating a
// reference to {rows} in "box".
$ptpl->set_block("box", "row", "rows");
// define the variables TITLE and PAGETITLE
$ptpl->set_var(array(
"TITLE" => "PHPLIB Template class example",
"PAGETITLE" => "Example page",
"CONTENT_TITLE" => "Content of example",
"CONTENT_ALIGN" => "center"));
// define NUM and BIGNUM, then append "row" to "rows"...
for ($i=1; $i<=3; $i++) {
$n = $i;
$nn = rand($i*5,$i*15);
$ptpl->set_var(array("NUM" => $n, "BIGNUM" => $nn));
$ptpl->parse("rows", "row", true);
}
// build out from box, then build out from page...
$ptpl->parse("OUT", array("box", "page"));
// finish out and print it.
$data = $ptpl->getParsedDoc("OUT");
echo $data;
$end = $ptpl->utime();
$runtime = ($end - $start) * 1000;
echo "<br>Completed in $runtime miliseconds<BR>\n";
// we write the file at the end so this
// operation will not be counted in the benchmark
$ptpl->write_to_cache($data);
?>
|