<?php
/* $Id: use_get_example2.php,v 1.1 2000/07/31 14:05:10 jesus Exp $ */
// call this script: get_exampl2.php?ctitle=Some+title&calign=center
// based on the example usins PHPLIB's template class
// demonstrates the use of the use_get() method to store
// the GET query string along w/ the parsed document
include("./phplib_template.inc");
include("./class.PHPLIBTemplateAdaptor.php");
include("./class.CachedTemplate.php");
echo "<hr>QUERY_STRING: ".$GLOBALS["QUERY_STRING"]."<hr>";
// create Template instance called $ptpl
$ptpl = new CachedTemplate();
$start = $ptpl->utime();
$ptpl->init(".", "keep");
// store the GET_STRING
$ptpl->use_get("store");
// 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
// ctitle and calign come from a GET query string
$ptpl->set_var(array(
"TITLE" => "PHPLIB Template class example",
"PAGETITLE" => "Example page",
"CONTENT_TITLE" => $ctitle,
"CONTENT_ALIGN" => $calign));
// 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);
?>
|