[SF home page] [Download] [Mailing list] [Forum] [wiki]
It's new template system for PHP. It's work only with PHP5, so I can't show same examples on this page - SF give only PHP4. Why this template system was different/better? It use XML-like look language, and you can call for templates method in your classes.
I know that this page is very ascetic. Sorry, I haven't to many time, and artistic talents. If you want, you can make same layout web.template main page (you can found e-miaĆ to me in web.template sources).
If you like web.template and if you're looking for same other power full stuff for PHP5, you can interesting web.framework - MVC framework for PHP5.
I looking for same one who help me write documentation for web.template. I want to work at this documentation on web.framework wiki. If you're interesting, you can register on this wiki, and write to me:-)
PHP file:
class User { public function getName() { // you can get it from DB for example return 'Marcin'; } public function getSurname() { // you can get it from DB for example return 'Staniszczak'; } public function getPhoto() { // you can get it from DB for example return 'mstaniszczak.jpg'; } } $tpl = new WebTemplate(); $tpl->setCacheDir('templates/cache/'); $tpl->setCompileDir('templates/compile/'); $tpl->setTemplateDir('templates/templates/'); $tpl->addVarClass("user", new User); $tpl->assign('Version', '1.0'); $tpl->assign('img', 'logo.gif'); $tpl->display('index.tpl', 'cache_id');
TPL file (index.tpl):
<img wt:src="{logo}"/> <br /> <img wt:src="{user.photo}" /> <wt:var name="user.name" /> <wt:var name="user.surname" /><br /> <wt:var name="version" /> It's product HTML like this: <img src="logo.gif"/> <br /> <img src="mstaniszczak.jpg" /> Marcin Staniszczak<br /> 1.0
Form now you can too use arrays of objects:
PHP file:
class User { private $name; private $surname; private $pict; public function __construct($name, $surname, $pict) { $this->name = $name; $this->surname = $surname; $this->pict = $pict; } public function getName() { // you can get it from DB for example return 'Marcin'; } public function getSurname() { // you can get it from DB for example return 'Staniszczak'; } public function getPhoto() { // you can get it from DB for example return 'mstaniszczak.jpg'; } } $tpl = new WebTemplate(); $tpl->setCacheDir('templates/cache/'); $tpl->setCompileDir('templates/compile/'); $tpl->setTemplateDir('templates/templates/'); //you can use too associate arrays $users = array( new User('Marcin', 'Staniszczak', 'mstaniszczak.jpg'), new User('Scott', 'Forge', 'sforge.jpg'), new User('Mark', 'Buges', 'mbuges.jpg'), ); $tpl->assignObjArray('users', $users); $tpl->assign('Version', '1.0'); $tpl->assign('img', 'logo.gif'); $tpl->display('index.tpl', 'cache_id');
TPL file (index.tpl):
<img wt:src="{logo}"/> <br /> <wt:foreach data="users" value="user"> <img wt:src="{user.photo}" /> <wt:var name="user.name" /> <wt:var name="user.surname" /><br /> </wt:foreach> <wt:var name="version" /> It's product HTML like this: <img src="logo.gif"/> <br /> <img src="mstaniszczak.jpg" /> Marcin Staniszczak<br /> <img src=" sforge.jpg" /> Scott Forge<br /> <img src=" mbuges.jpg" /> Mark Buges<br /> 1.0
Why you should use classes with getter, not assign variables? If you not always need same variables (for example in conditionals constructions - <wt:if ...>), gutter guaranty that template call this method only when data given by this getter will be really needed - so only when condition form <wt:if ...> was grant.
And at the end - sorry for my English... If you have same free time, you can correct this text and send me it back.