Unlike other PHP 5 template engines, OPT does not have a native singleton design pattern implemented.
Thanks to this fact, you may extend the default optClass with additional methods, and
add this pattern manually, if you really need it. Let's take a look at the sample aplication that extends the
base class and adds some commonly used parts of code to the OPT.
Example 1.2. Advanced installation
<?php
define('OPT_DIR', '../lib/');
require('../lib/opt.class.php');
class myParser extends optClass
{
public $pageTitle;
public function __construct()
{
$this -> root = './templates/';
$this -> compile = './templates_c/';
$this -> cache = './cache/';
$this -> gzipCompression = 1;
$this -> httpHeaders(OPT_HTML);
} // end __construct();
public function display($template)
{
$this -> assign('pageTitle', $this -> pageTitle);
$this -> parse('overall_header.tpl');
$this -> parse($template);
$this -> parse('overall_footer.tpl');
} // end display();
}
try
{
$tpl = new myParser;
$tpl -> pageTitle = 'My page';
$tpl -> assign('current_date', date('d.m.Y, H:i'));
$tpl -> display('document.tpl');
}
catch(optException $exception)
{
optErrorHandler($exception);
}
?> Using this way, you may extend the engine with additional features or enclose some commonly made operations in additional methods.