11-02-2008, 09:42 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by codefreek
mate, you are totally of topic ;P
|
Not really, whats wrong with something like this:
PHP Code:
<?php class template { private $aVarStack = array(); private $szTplFile; public function __construct($szTplFile) { $this->szTplFile = $szTplFile; } public function __set($szKey, $mValue) { $this->aVarStack[$szKey] = $mValue; } public function __get($szKey) { if(!array_key_exists($szKey, $this->aVarStack)) { throw new Exception($szKey . 'is an invalid template variable'); } return $this->aVarStack[$szKey]; } public function display() { include $this->szTplFile . '.phtml'; } }
Now the tpl file:
PHP Code:
<h1><?php echo $this->header; ?></h1> <p><?php echo $this->content; ?></p>
And now the driver:
PHP Code:
<?php require('template.php'); try { $tmp = new template('template'); $tmp->header = 'this is a header'; $tmp->content = 'This is some content'; $tmp->display(); } catch(Exception $e) { echo 'Error in template: ', $e->getMessage(); }
Its not perfect but at least you don't need to waste the time parsing tpl files for special tokens and then injecting data into them, after all ZendFramework seems to be ok with it.
For if statements/loops etc just use PHP:
PHP Code:
<html> ... <?php if($name == 'Sam'):?> <p>Do something here for Sam?</p> <?php endif;?>
... </html>
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|