Location: PHPKode > scripts > Template Manager > template-manager/example.php
<?php
/******************************************************
** loads a Template and changes %OUT% to passesVars['OTU']
** or arrays %OUT.hello% passesVars['OUT']['hello']
** to unlimited depth
******************************************************/
include("template.php");
/******************************************************
**						Example 1
******************************************************/
$tpl = new template();

$tpl->setName("test"); //sets path to templates/test/
$tpl->setFile("test"); //provides test.tpl inside path

$output = array('OUT' => 'this is an output');

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

/******************************************************
**						Example 2
******************************************************/
$tpl = new template();

$tpl->setFile("test"); //provides test.tpl inside path

$output = array('OUT' => 'this is an output');

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

// please notice this dose not have $tpl->setName("test"); this will then use templates/default/

/******************************************************
**						Example 3
******************************************************/
$tpl = new template();

$output = array('OUT' => 'this is an output');

$tpl->setName("test"); //provides file path as templates/test

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

// Please notice this dose not have $tpl->setFile("test"); this will then use the default index.tpl

/******************************************************
**						Example 4
******************************************************/
$tpl = new template();

$tpl->setName("test"); //sets path to templates/test/
$tpl->setFile("test"); //provides test.tpl inside path

echo $tpl.render(); // renders the output
// Please Notice There is not $tpl.passVars($output); or $tpl->passVar('OUT', 'this is an output');
// this will then cause the class to use $GLOBALS for the array

/******************************************************
**						Example 5
******************************************************/
$tpl = new template("test", "test"); //sets path to templates/test/, provides test.tpl inside path

$output = array('OUT' => 'this is an output');

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output


/******************************************************
**						Example 6
******************************************************/
$output = array('OUT' => 'this is an output');

$tpl = new template("test", "test", $output); //sets path to templates/test/, provides test.tpl inside path

echo $tpl->render(); // renders the output

/******************************************************
**						Example 7
******************************************************/
$output = array('OUT' => 'this is an output');

echo $tpl = new template("test", "test", $output, $true); //sets path to templates/test/, provides test.tpl inside path and returns the source to output
?>
Return current item: Template Manager