Location: PHPKode > scripts > Templateze > templateze/instructions.html
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Templateze Overview</title>
<style>
<!--
h1
	{
	margin:0cm;
	margin-bottom:.0001pt;
	page-break-after:avoid;
	font-size:10.0pt;
	font-family:"Times New Roman";
	color:windowtext;
	font-weight:bold;}
-->
</style>
</head>

<body>

<p align="center"><b><i><font size="4" color="#000080">Templateze Overview</font></i></b></p>
<p>A very simple and quick template engine that allows php developers to 
separate html from php code.</p>
<p>----------------------<br><b>Example 1</b><br>----------------------<br>
<font color="#000080">Quick variable 
replacement and template display</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include(&quot;templateze.php&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl = new templateze(&quot;./example.html&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl-&gt;set(&quot;var1|$var1&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl-&gt;set(&quot;var2|$var2&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl-&gt;set(&quot;var3|$var3&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
echo $tpl-&gt;display();<br>

<p>----------------------<br><b>Example 2</b><br>----------------------<br>
<font color="#000080">Change replacement tags, variable 
replacement and template display</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include(&quot;templateze.php&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl = new templateze(&quot;./example.html&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $tpl-&gt;tagchange(&quot;%&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl-&gt;set(&quot;var1|$var1&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
echo $tpl-&gt;display();

<p>----------------------<br><b>Example 3</b><br>----------------------<br>
<font color="#000080">Loop replacement</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include(&quot;templateze.php&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$tpl = new templateze(&quot;./example.html&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$table_rows = array();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $table_rows[] = array( 'id' =&gt; '1',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'first_name' =&gt; 'John',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'surname' =&gt; 'Smith'<br>
&nbsp;&nbsp;&nbsp; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $table_rows[] = array( 'id' =&gt; '2',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'first_name' =&gt; 'Bill',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'surname' =&gt; 'Jones'<br>
&nbsp;&nbsp;&nbsp; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $table_rows[] = array( 'id' =&gt; '3',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'first_name' =&gt; 'Tom',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'surname' =&gt; 'Robins'<br>
&nbsp;&nbsp;&nbsp; );<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $tpl-&gt;setloop(&quot;table_rows&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
echo $tpl-&gt;display();

<p>----------------------<br><b>Example 4</b><br>----------------------<br>
<font color="#000080">Grab the contents of a second file and insert it into the 
template.</font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include(&quot;templateze.php&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $tpl = new templateze(&quot;./example.html&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $tpl-&gt;tplblock(&quot;header|./template_head.html&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
echo $tpl-&gt;display();

<p>&nbsp;<hr>
<p>When working with templates most of the time there are three types of basic 
needs</p>
<ol>
	<li>Variable Replacement</li>
	<li>Loops for building dynamic tables</li>
	<li>Blocks for including code from different templates</li>
</ol>
<p>Templateze makes use of the above using very simple functions.</p>
<p>&nbsp;&nbsp;&nbsp; $tpl-&gt;set(KEY|$VAR)<br>&nbsp;&nbsp;&nbsp; $tpl-&gt;setloop(LOOPNAME)<br>&nbsp;&nbsp;&nbsp; $tpl-&gt;tplblock(KEY|TEMPLATE)</p>

<p align="center"><b><font color="#000080">Templateze Demo Explained</font></b></p>
<p align="left"><font color="#000080"><b>$tpl = new templateze(&quot;./example.html&quot;);</b></font><br>
This will initiate the class and load the template into memory.

A relative or full server path can be used to locate the template.</p>
<font color="#000080"><b>$tpl-&gt;set(&quot;var1|$var1&quot;);</b></font>

<br>Sets both the key and variable seperated by the 
deliminator | and then changes the key within the template.</p>
<p><font color="#000080"><b>$tpl-&gt;tagchange(&quot;%&quot;);<br></b></font>Changes the tags 
to search for within the template. Default tag is set to ~&nbsp; IE: ~KEY~</p>
<p><font color="#000080"><b>$tpl-&gt;setloop(&quot;table_rows&quot;);<br></b></font>This 
parses the defined loop called table_rows using a previously defined array of 
the same name.</p>
<p><font color="#000080"><b>$tpl-&gt;tplblock(&quot;header|./template_head.html&quot;);<br></b></font>This 
sets the key (header) and replaces that with the contents of template_head.html</p>
<p><font color="#000080"><b>echo $tpl-&gt;display();<br></b></font>Returns and displays the 
complete template.</p>
<p>&nbsp;</p>

</body>

</html>
Return current item: Templateze