Re: Play nice! Re: Savant/Flexy/Foo template engines
| From: | Paul M Jones | Date: | Thu, 10 Jun 2004 23:30:32 +0000 |
| Subject: | Re: Play nice! Re: Savant/Flexy/Foo template engines | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-30447@lists.php.net to get a copy of this message | ||
On Jun 10, 2004, at 3:55 PM, Paul M Jones wrote:
On Jun 10, 2004, at 3:50 PM, Joshua Eichorn wrote:Here's a quick example of how the "minimalist" one might work; Alan can post how his "core provides" might work, and we can compare from there. I'm very open to changes on this; it's not really in stone. <?php // data for the template $data = new StdClass; $data->text = 'xxxx'; // instead of 3 lines in "normal" Flexy... $template = new HTML_Template_Flexy(); $template->compiler('/name/of/template.html'); $template->outputObject($data,$elements) // or 3 lines in "normal" Savant... $Savant =& new Savant(); $Savant->assign('t', $data); $Savant->display('/name/of/template.html'); // use 5 lines for Common Jausions Interface template system. $tpl =& new Template(); $tpl->compiler =& new Template_Compiler_Flexy(); $tpl->openTemplate('/name/of/template.html'); $tpl->setData('t', $data); $tpl->output(); // the compiler is swappable. $tpl =& new Template(); $tpl->compiler =& new Template_Compiler_Savant(); $tpl->openTemplate('/name/of/template.html'); $tpl->setData('t', $data); $tpl->output(); // a custom wrapper can reduce the call-time lines even further. class Template_Special extends Template { require_once 'Template/Compiler/Special.php'; function Template_Special($opts = array()) { parent::Template(); $this->compiler =& new Template_Compiler_Special($opts); } function display($tpl, $obj) { $this->openTemplate($tpl); $this->setData($obj); $this->output(); } } $tpl =& new Template_Special(); $tpl->display('/name/of/template.html', $data); // adding filters is easy in the minimalist model $tpl =& new Template_Special(); $tpl->filters[] = array('/\<\!\-\- (.+?) \-\-\>/', ''); // remove HTML comments $tpl->display('/name/of/template.html', $data); ?> -- Paul M. Jones Savant: the simple alternative to Smarty for PHP. http://phpsavant.com/ DB_Table: build RDBMS tables and XHTML forms in one PHP class. http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table Yawiki: your collaborative online documentation system. http://yawiki.com/ Yawp: a single-file foundation for PHP applications. http://phpyawp.com/I've been crazy busy at work for the last couple days so i haven't had a time to review the code but i would point out that an interface and extension isn't the only solution.Fair enough; when you get a chance, take a look at both sets -- they seem to follow distinctly different paths, even though we're using the same reference document (the Jausions interface model). What would other solutions be, besides interface and extension? Maybe I'm too much inside the box, I thought those were two principal ideas in OOP-like code.What you need is a decent api and the ability to support lots of features without lots of overhead over or a really complicated api. Using other patterns then just an interface and inheiritance may be a better way to go.It may be that they both have that; Alan's seems to incorporate more into the base class for compiler control and loading, while mine seems to incorporate more for assignment and return. I've got a "placeholder" for a compiler object that gets built and configured externally to the template object itself, while Alan has a "placeholder" for assignment objects.