#native_company# #native_desc#
#native_cta#

HTML Template Library

By Richard J. Marini
on March 7, 2001

Version: 1.0

Type: Sample Code (HOWTO)

Category: HTML

License: GNU General Public License

Description: HTML template library for abstracting logic from html interfaces. Acts like your standard template library except provides for callback handlers for template variables amount some other nifty features.

Bascially in it's simplest  an implementation might look like this.....

/* callback handler for template variable */
function generate_name($key, $value,  $argv,  $output_string,  $return_data)
{
   $ret_status= new status();  /* we use a status object for error hanlding, also included in the library */

   /* do some dynamic stuff here */
   $dynamic_stuff= "":

   /*
       here we would assign the dynamic stuff to output_string, output_string is the data that will
       replace the template variable in the template 
  */
   $output_string= $dynamic_stuff;

return $ret_status->Ok;  /* if an error occured we would return $ret_status->Error */
}

/*---------
   Main, Start
----------*/
$template= new Template("mytemplate.tmpl");   /* create new template object */

/* add template variables values or assign callback handlers to template variables */
$template->AddVar("myvar", "hello");  /* adding a value */
$template->AddVar("myvar2",  NULL, "generate_name");  /* assigning a callback to generate the value */

/*
   serve the template, this parses the template and calls all the callbacks and does the replacement of
   the template variables within the template then returns the parsed template in output_string
*/
$template->Serve(&$html_output,  &$return_data);

/* display the template */
print $html_output; 

The full version and assorted examples can be downloaded from <a href="http://unlser1.unl.csi.cuny.edu/~marini/index.cgi">unlser1.unl.csi.cuny.edu/~marini/index.cgi</a>.
There are still some features (especially in the error object) that I want to implement.  Probably some bugs to.

have fun, 
-richie [email protected]