PHP Classes

File: xtemplate_ex5.php

Recommend this page to a friend!
  Classes of Jesus M. Castagnetto   Generalized CachedTemplate class   xtemplate_ex5.php   Download  
File: xtemplate_ex5.php
Role: ???
Content type: text/plain
Description: Example using the XTemplate class
Class: Generalized CachedTemplate class
General Template Caching class
Author: By
Last change:
Date: 23 years ago
Size: 1,849 bytes
 

Contents

Class file image Download
<?php /* * $Id: xtemplate_ex5.php,v 1.3 2000/07/16 19:33:46 jesus Exp $ */ /* example 5 demonstrates nullstrings */ require "./xtpl.php"; require "./class.XTemplateAdaptor.php"; require "./class.CachedTemplate.php"; $xtpl=new CachedTemplate(); $xtpl->init("ex5.xtpl"); // for benchmarking $start = $xtpl->utime(); // Check if we can send the cached file if ($xtpl->valid_cache_file($filename)) { echo "<B>FROM CACHE</B>\n<BR>"; $xtpl->read_from_cache($filename); $end = $xtpl->utime(); $runtime = ($end - $start) * 1000; echo "Completed in $runtime miliseconds<BR>\n"; exit; } $xtpl->assign(INTRO_TEXT,"by default, if some variables weren't assigned a value, they simply disappear from the parsed html:"); $xtpl->parse("main.form"); $xtpl->assign(INTRO_TEXT,"ok, now let's assign a nullstring:"); $xtpl->SetNullString("value not specified!"); $xtpl->parse("main.form"); $xtpl->assign(INTRO_TEXT,"custom nullstring for a specific variable and default nullstring mixed:"); $xtpl->SetNullString("no value.."); $xtpl->SetNullString("no email specified!",EMAIL); $xtpl->parse("main.form"); $xtpl->assign(INTRO_TEXT,"custom nullstring for every variable:) .. you should get it by now. :P"); $xtpl->SetNullString("no email specified",EMAIL); $xtpl->SetNullString("no name specified",FULLNAME); $xtpl->SetNullString("no income?",INCOME); $xtpl->parse("main.form"); $xtpl->parse("main"); // get parsed document $data = $xtpl->getParsedDoc("main"); // output the page echo $data; // for benchmarking $end = $xtpl->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 $xtpl->write_to_cache($data); ?>