<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"><html><head><title>{:TITLE:}</title></head>
<body>
{:MYTAG:}
</body>
</html>
</div>
view.php
<div class="box"><?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->Template("main", "templatefile.tpl");
/* Set the TITLE tag value */
$tpl->SetTag("TITLE", "Testing testing 1 2 3");
/* Set the MYTAG tag value */
$tpl->SetTag("MYTAG", "This was easy!");
/* Print the finished template */
print $tpl->PrintTPL();
?>
</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"><html><head><title></title></head>
<body>
{:IMAGEFILE:}
</body>
</html>
</div>
image.tpl
<div class="box"><img src="apicture.png" border="{:BORDERSIZE:}"></div>
view.php
<div class="box"><?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->Template("main", "t.tpl");
/* Tell the class to use image.tpl,
and set its "name" to 'theimagetpl' */
$tpl->Template("theimagetpl", "image.tpl");
/* Set the BORDERSIZE tag value to 4 */
$tpl->SetTag("BORDERSIZE", "4");
/* Paste the image template to the IMAGEFILE tag
in the 'main' template */
$tpl->Paste("IMAGEFILE", "theimagetpl");
/* Print the finished template */
print $tpl->PrintTPL("main");
?>
</div>
run the view.php script
******************************************************
Example 3 - Dynamic blocks
******************************************************
Create two files: t.tpl and view.php
t.tpl
<div class="box"><html><head><title>{:TITLE:}</title></head>
<body>
<table border="1">
<!-- DYNSTART:mydynamicblock -->
<tr><td>{:DATA:}</td></tr>
<!-- DYNEND:mydynamicblock -->
</table>
</body>
</html>
</div>
view.php
<div class="box"><?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->Template("main", "t.tpl");
/* Generate som data, and build a dynamicdata list */
for ($i=0;$i<10;$i++) {
/* Set the DATA tag */
$tpl->SetTag("DATA", $i);
/* Append new data to the dynamic list */
$tpl->AppendDynamic("mydynamicblock");
}
/* Parse the dynamiclist in the dynamic block */
$tpl->ParseDynamic("mydynamicblock");
/* Print the finished template */
print $tpl->PrintTPL("main");
?>
</div>
<div class="listheader">Notes!</div>
Dynamic blocks should start with <!-- DYNSTART:xxxxx -->
And end with <!-- DYNEND:xxxxx -->
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.
<!-- DYNSTART:main -->
{:TAG:}
<!-- DYNEND:main -->
---
<?php
...
$tpl->Template("main", "tpl/file.tpl");
?>
.....will mess things up.
</pre>