Location: PHPKode > scripts > Generalized CachedTemplate class > use_get_example2.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


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

// define variables named page and box, referencing files
	"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>";
    $end = $ptpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "<br>Completed in $runtime miliseconds<BR>\n";

// 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
	"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
Return current item: Generalized CachedTemplate class