Location: PHPKode > scripts > Template Interface Engine > template-interface-engine/sample3_4.php
<?php
	include 'interface4.class.php';

	$color = array('black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'yellow', 'aqua', 'white');

	$time_start = getmicrotime();

	$desktop = new CInterface('sample3.html');

//this is how variable escaping will not be parsed in template file.
//look around inside the template file
	$desktop->Var[variable1] = "Hello World!";
	$desktop->Var[variable2] = 32547536354;
	$desktop->Var[variable3] = $desktop->Var[variable1];

//the trick to show/hide the messagebox
	if(isset($_POST[Submit])) $desktop->Var[thetext] = htmlspecialchars(stripslashes($_POST[entrytxt]));

//this will show: ********** Table 1 **********
	$table1 = new CInterface('tablex.html');
	$table1->Var[nom] = 1;
	$table1->Var[data] = array(
							array('Norman The Ludwig', 'Straight St.', 'hide@address.com'),
							array('Clark Kent', 'Mountana Hill', 'hide@address.com'),
							array('Peter Parker', 'Jakarta St', 'hide@address.com'),
							array('Robin Hood', 'Pahlawan Pedestrian', 'hide@address.com')
						);
	$table1->RegisterFunction(create_function('$row', 'return ($row + 1);'), 'data_nom');
	$desktop->Var[table1] = $table1->Output('_PIPE');

//this will show: ********** Table 2 **********
	$table2 = new CInterface('tablex.html');
	$table2->Var[nom] = 2;
	$table2->Var[data] = array();
	$desktop->Var[table2] = $table2->Output(_PIPE);



//Table 3 and Table 4 will show the same appearance, but with different ways to show it
//the one brings the logic in PHP part, and the other brings the logic in template part

//this will show: ********** Table 3 **********
	$table3 = new CInterface('tablec1.html');
	$table3->Var[nom] = 3;
	$table3->Var[color] = array_chunk($color, 1);
	function table3_color($data) {
		if($data[0] == 'red') $data[1] = 'This is red';
		elseif($data[0] == 'green') $data[1] = 'And this is GREEN color';
		elseif($data[0] == 'blue') $data[1] = 'Here is Blue row';
		else $data[1] = '&nbsp;';

		return $data;
	}
	$table3->RegisterFunction('table3_color', 'color');
	$desktop->Var[table3] = $table3->Output(_PIPE);

//this will show: ********** Table 4 **********
	$table4 = new CInterface('tablec2.html');
	$table4->Var[nom] = 4;
	$table4->Var[color] = array_chunk($color, 1);
	$desktop->Var[table4] = $table4->Output(_PIPE);

//printout the desktop output
	$out = $desktop->Output(_PIPE, false);

//calculate execution time
	$time_end = getmicrotime();
	print '<div align="center"><font size="2">Execution Time: '.($time_end - $time_start).' seconds</font></div>';

//then print out the output
	print $out;

	function getmicrotime() {
	   list($usec, $sec) = explode(" ",microtime());
	   return ((float)$usec + (float)$sec);
	}
?>
Return current item: Template Interface Engine