Location: PHPKode > scripts > Template Interface Engine > template-interface-engine/sample3.php
<?php
	include 'interface.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->variable1 = "Hello World!";
	$desktop->variable2 = 32547536354;
	$desktop->variable3 = $desktop->variable1;

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

//this will show: ********** Table 1 **********
	$table1 = new CInterface('tablex.html');
	$table1->nom = 1;
	$table1->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->table1 = $table1->Output('_PIPE');

//this will show: ********** Table 2 **********
	$table2 = new CInterface('tablex.html');
	$table2->nom = 2;
	$table2->data = array();
	$desktop->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->nom = 3;
	$table3->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->table3 = $table3->Output(_PIPE);

//this will show: ********** Table 4 **********
	$table4 = new CInterface('tablec2.html');
	$table4->nom = 4;
	$table4->color = array_chunk($color, 1);
	$desktop->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