Re: QuickForm and templates RFC
| From: | Alexey Borzov | Date: | Thu, 20 Feb 2003 21:25:33 +0000 |
| Subject: | Re: QuickForm and templates RFC | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-13527@lists.php.net to get a copy of this message | ||
Bertrand Mansion wrote:
Hi, Today, QuickForm has been released in version 2.9. This version is IMO quite stable and a lot of old bugs or problems have been fixed, making QuickForm work as expected in most cases. I think it's now time to think about new features. The first one I would like to implement is a template bridge so that you won't need to care anymore about element and form templates or layout in your code. Do you have any ideas on how this could be done ? In fact I do have some ideas. :]The simplest solution would seem to be just create a template for each form you use and call the templates' engine methods instead of doing echo $element->toHtml(). In fact, some time ago I hacked QuickForm to use IT[X] instead of outputting HTML directly. But there is a problem with this solution: 1) It is a hack, you can't use any other template engine; 2) It quickly gets boring to make templates for each form, they tend to be quite similar looking. :] The cleaner solution (that I thought about for some time, but never tried to implement) would be to have a bridge-type object, lets call it QuickForm_Renderer. The simplest one would be the current "internal" renderer of QuickForm, but also there can be QuickForm_Renderer_ITX, QuickForm_Renderer_Smarty, etc. The renderer itself would implement a Visitor pattern, with methods like visitElement(), visitHeader(), visitGroup(), etc And the template can be more like a "meta-template": <!-- BEGIN default_input --> <tr> <td>{element_label}<!-- BEGIN element_error_block --><span class="very_red">{element_error}</span><!-- END element_error_block --></td> <td>{element_html}</td> </tr> <!-- END default_input --> The renderer would use the default template for element, unless explicitly told to use some other: <!-- BEGIN special_input --> <tr> <td colspan="2">{element_label}<br>{element_html}</td> </tr> <!-- END special_input -->