Location: PHPKode > scripts > Template Processor > template-processor/example_build.php
<?php
	/**
	 * Load class
	 */
	require_once("./template.class.php");

	/**
	 * Make object instance and set 'vartype' to 'php' (from v1.0.2)
	 */
	$temp = new Template(Array('vartype' => 'php'));

	/**
	 * This is some dummy data we're later gonna 
	 * run though a foreach
	 */
	$data = Array(
			Array(
				'Kalle', 
				17
				), 
			Array(
				'Joe', 
				29
				)
			);

	/**
	 * Add some random markup that will appear as 
	 * a header of some sort
	 */
	$temp->addcache('<div><h3>Top Programmers</h3><ul>');

	/**
	 * You may call $temp->clear_cache(true) to clear the
	 * build cache before using it, but since we havn't in 
	 * this example we don't
	 */

	/**
	 * Run the foreach
	 */
	foreach($data as $info)
	{
		/**
		 * Add some template cache into the 'build' cache
		 */
		$temp->addcache("<li>Name: \$name<br/>Age: \$age</li>", true);

		/**
		 * Replace variables in 'build' cache
	 	 *
		 *	Note. that we dont set the option to replace
		 *	'phpvars' in the replace_var() function (<= v1.0.1 only)
		 *
		 */
		$temp->replace_var('name', $info[0], false, true);
		$temp->replace_var('age', $info[1], false, true);

		/**
		 * Build current cache, build() will clear the cache when its done
		 */
		$temp->build();
	}

	/**
	 * Add some random markup that will appear as 
	 * a footer of some sort
	 */
	$temp->addcache('</ul></div>');

	/**
	 * Compile example
	 */
	$temp->compile();

	/**
	 * HTML Dump should be something like this:
	 *
	 *	<div>
	 *		<h3>Top Programmers</h3>
	 *		<ul>
	 *			<li>
	 *				Name: Kalle<br/>Age: 17
	 *			</li>
	 *			<li>
	 *				Name: Joe<br/>Age: 29
	 *			</li>
	 *		</ul>
	 *	</div>
	 *
	 */
?>
Return current item: Template Processor