PHP Classes
Icontem

File: herman_example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  herman_example.php  
File: herman_example.php
Role: ???
Content type: text/plain
Description: Example using HTML Template class
Class: Generalized CachedTemplate class
General Template Caching class
 

Contents

Class file image Download
<?php
/*
 * $Id: herman_example.php,v 1.3 2000/07/16 19:33:46 jesus Exp $
 */
/*
 * A modification of the example from Herman's HTML Template class -- JMC
 */

require "./herman_template.inc";
require "./class.HTMLTemplateAdaptor.php";
require "./class.CachedTemplate.php";

$htpl = new CachedTemplate();
// no need to use $htpl->init(), because the 
// HTML_Template class has no constructor

// for benchmarking
$start = $htpl->utime();

?>
<html>
<head>
<title>Test of Template Class</title>

<STYLE TYPE="text/css">
  .listHead { font: bold 12pt sans-serif; background: #cccc99;}
  .listData { font: normal 12pt sans-serif;}
  .listDark { background: #eeeeee; }
  .listLite { background: #dddddd; }
  .list-bg { background: #333333; }
</STYLE>

</head>

<body>
<?php
// Check if we can send the cached file
if ($htpl->valid_cache_file()) {	// if there is a valid cache file

	echo "<B>FROM CACHE</B>\n<BR>";
    $htpl->read_from_cache();
    $end = $htpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "Completed in $runtime miliseconds<BR>\n";
	
} else {	// process the template and create a new cache file

	$primary = array(
					array("ABC",2.44,2.45,2.5),
					array("DEF",1.2,1.4,1.45),
					array("HIJ",2.44,2.45,2.5),
					array("KLM",6.55,6.66,6.7),
					array("MNO",2.34,2.5,2.7),
					array("PQR",3.4,4.45,4.5));
					
	$secondary = array(
					array("LMN10",5432.456,3344.123,8.546),
					array("PQR20",8945.366,6066.422,45.454),
					array("TUV40",3553.646,244.533,576.5443),
					array("XYZ10",5476.333,3234.235,434.675));

	$htpl->file_name = "herman_template.html";
	$htpl->get_templates();
	$htpl->toggle = array('Dark', 'Lite'); //used for alternating backgrounds for example.

	//assign data to array entry with key same as template name.
	$htpl->template['primary']['data'] = $primary; 
	$htpl->template['secondary']['data'] = $secondary;

	$htpl->code();

	// get parsed document
	$data = $htpl->getParsedDoc();

	// output the page
	echo $data;

	// for benchmarking
	$end = $htpl->utime();
	$runtime = ($end - $start) * 1000;
	echo "Completed in $runtime miliseconds<BR>\n";


	// we write the file at the end so this
	// operation will not be counted in the benchmark
	$htpl->write_to_cache($data);
}

?>
</body>
</html>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products