PHP Classes

File: richard_example.php

Recommend this page to a friend!
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  richard_example.php  >  Download  
File: richard_example.php
Role: ???
Content type: text/plain
Description: Example using Richard's Template class
Class: Generalized CachedTemplate class
General Template Caching class
Author: By
Last change:
Date: 22 years ago
Size: 1,958 bytes
 

Contents

Class file image Download
<?php
/*
 * $Id: richard_example.php,v 1.3 2000/07/16 19:33:46 jesus Exp $
 */

/*
 * Based on "seperate.php" (sic) example file by R. Heyes
 * from the Template class package -- JMC
 */

require "class.template.inc";
require "./class.RHTemplateAdaptor.php";
require "./class.CachedTemplate.php";

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

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

$tpl->load_file('header', 'header-template.html');
$tpl->load_file('main', 'main-template.html');
$tpl->load_file('footer', 'footer-template.html');

// Check if we can send the cached file
if ($tpl->valid_cache_file()) {
	echo "<B>FROM CACHE</B>\n<BR>";
    $tpl->read_from_cache();
    $end = $tpl->utime();
    $runtime = ($end - $start) * 1000;
    echo "Completed in $runtime miliseconds<BR>\n";
	exit;
}

// otherwise process the templates with some data

/* data for the templates */
$test_var = 'Hello world!';
$page_title = 'Template Class';

$table_rows = array();
$table_rows[] = array( 'column_1' => 'This is column one on row one!',
					   'column_2' => 'This is column two on row one!',
					   'column_3' => 'This is column three on row one!'
					 );

$table_rows[] = array( 'column_1' => 'This is column one on row two!',
					   'column_2' => 'This is column two on row two!',
					   'column_3' => 'This is column three on row two!'
					 );

$tpl->register('header', 'test_var,page_title');

$tpl->parse('header');
$tpl->parse_loop('main', 'table_rows');

// get parsed document
$data = $tpl->getParsedDoc("header,main,footer");

// output the page
echo $data;

// for benchmarking
$end = $tpl->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
$tpl->write_to_cache($data);
?>
For more information send a message to info at phpclasses dot org.