Location: PHPKode > scripts > EasyTPL > easytpl/example7/tpl/howto.tpl
<pre>

<div class="listheader">::: Class functions :::</div>

class EasyTPL($path == NULL)
	- Construct (and set template 'root' path)

function Template($handle, $file)
	- Defines templates

function SetTag($tag, $value)
	- Sets a tag value

function Paste($tag, $handle)
	- Paste a template into a tag

function PasteText($tag, $handle)
	- Paste a HTML file as text into a tag

functin AppendDynamic($handle)
	- Appends new dynamic data to the dynamiclist of the handle

function ParseDynamic($handle)
	- Parse the dynamiclist of the handle into the dynamicblock

function PrintTPL($handle == NULL)
	- Return the finished document
	- Returns the handle document if set, the first handle as default

function _clear_dynamic($handle)
	- Internal. But if you need it, it cleans out the dynamiclist of the handle





<div class="listheader">::: Some examples :::</div>
(Look in the example directories for some examples)

******************************************************
Example 1 - simple tag
******************************************************
Create two files: templatefile.tpl and view.php

templatefile.tpl
<div class="box">&lt;html&gt;&lt;head&gt;&lt;title&gt;{:TITLE:}&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
	{:MYTAG:}
&lt;/body&gt;
&lt;/html&gt;
</div>

view.php
<div class="box">&lt;?php
	/* include the class */
	require_once("class.EasyTPL.php");

	/* create a new object */
	$tpl = new EasyTPL();

	/* Tell the class to use templatefile.tpl, 
		and set its "name" to 'main' */
	$tpl-&gt;Template("main", "templatefile.tpl");

	/* Set the TITLE tag value */
	$tpl-&gt;SetTag("TITLE", "Testing testing 1 2 3");

	/* Set the MYTAG tag value */
	$tpl-&gt;SetTag("MYTAG", "This was easy!");

	/* Print the finished template */
	print $tpl-&gt;PrintTPL();
?&gt;
</div>
run the view.php script



******************************************************
Example 2 - Multiple templates
******************************************************
Create three files: t.tpl, image.tpl and view.php

t.tpl
<div class="box">&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
	{:IMAGEFILE:}
&lt;/body&gt;
&lt;/html&gt;
</div>

image.tpl
<div class="box">&lt;img src="apicture.png" border="{:BORDERSIZE:}"&gt;</div>

view.php
<div class="box">&lt;?php
	/* include the class */
	require_once("class.EasyTPL.php");

	/* create a new object */
	$tpl = new EasyTPL();

	/* Tell the class to use t.tpl, 
		and set its "name" to 'main' */
	$tpl-&gt;Template("main", "t.tpl");

	/* Tell the class to use image.tpl, 
		and set its "name" to 'theimagetpl' */
	$tpl-&gt;Template("theimagetpl", "image.tpl");

	/* Set the BORDERSIZE tag value to 4 */
	$tpl-&gt;SetTag("BORDERSIZE", "4");

	/* Paste the image template to the IMAGEFILE tag 
		in the 'main' template */
	$tpl-&gt;Paste("IMAGEFILE", "theimagetpl");

	/* Print the finished template */
	print $tpl-&gt;PrintTPL("main");
?&gt;
</div>
run the view.php script




******************************************************
Example 3 - Dynamic blocks
******************************************************
Create two files: t.tpl and view.php

t.tpl
<div class="box">&lt;html&gt;&lt;head&gt;&lt;title&gt;{:TITLE:}&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;

&lt;table border="1"&gt;
&lt;!-- DYNSTART:mydynamicblock --&gt;
&lt;tr&gt;&lt;td&gt;{:DATA:}&lt;/td&gt;&lt;/tr&gt;
&lt;!-- DYNEND:mydynamicblock --&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;
</div>

view.php
<div class="box">&lt;?php
	/* include the class */
	require_once("class.EasyTPL.php");

	/* create a new object */
	$tpl = new EasyTPL();

	/* Tell the class to use t.tpl, 
		and set its "name" to 'main' */
	$tpl-&gt;Template("main", "t.tpl");

	/* Generate som data, and build a dynamicdata list */
	for ($i=0;$i&lt;10;$i++) {
		/* Set the DATA tag */
		$tpl-&gt;SetTag("DATA", $i);

		/* Append new data to the dynamic list */
		$tpl-&gt;AppendDynamic("mydynamicblock");
	}

	/* Parse the dynamiclist in the dynamic block */
	$tpl-&gt;ParseDynamic("mydynamicblock");

	/* Print the finished template */
	print $tpl-&gt;PrintTPL("main");
?&gt;
</div>




<div class="listheader">Notes!</div>

Dynamic blocks should start with &lt!-- DYNSTART:xxxxx --&gt;
And end with &lt!-- DYNEND:xxxxx --&gt;
where xxxxx is a name you choose.

Do not use handle names more than once in the same 'presentation'.
And do not use the same dynamic-block-names as template-handle-names

e.g.
&lt;!-- DYNSTART:main --&gt;
{:TAG:}
&lt;!-- DYNEND:main --&gt;

---

&lt;?php
	...
	$tpl->Template("main", "tpl/file.tpl");
?>

.....will mess things up.




</pre>
Return current item: EasyTPL