The template system I use is extremely simple.

Template.php:
<?php
class Template
{
        var $Items;
        var $_document;

        function Template($document)
        {
                $this->Items = array();
                $this->_document = $document;
        }

        function Render()
        {
                echo $this->ToString();
        }

        function ToString()
        {
                $template = $this->Items;
                ob_start();
                require($this->_document);
                return ob_get_clean();
        }
}
?>

and to use it?

templates/index.html:
<html>
<head></head>
<body>
Hello <?=$template['name']?>, it is currently <?=$template['time']?>
</body>
</html>

index.php:
<?php
include_once('Template.php');
$template = new Template('./templates/index.html');
$template->Items['name'] = 'User';
$template->Items['time'] = date('d M Y', time());
$template->Render();
?>

why use it?

Because you keep your html and your php code separate. That is the
goal when using any templating system.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to