HTML_Template Interface recommendation
| From: | Philippe Jausions | Date: | Fri, 07 May 2004 23:30:01 +0000 |
| Subject: | HTML_Template Interface recommendation | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-28990@lists.php.net to get a copy of this message | ||
Hi all,
Given the multiplication of the template engines, I suggest that PEAR also now provides interface definitions. This goes with PHP5 and could provide an added benefit to package that would need to generate content.
Conceptually template engines don't work the same way, but they all provide the same service, that is take some input and return (or output) some content... Now imagine an application that needs to send e-mails. The best way IMHO is to use template e-mail messages. Now the application could accept a template engine instance, an e-mail template and some data. The application would ask the template engine to generate the e-mail message using the template and the data. Currently, you have to write your application with a certain template engine in mind. I don't think this is acceptable, especially when your application is to be included in a larger framework, or you want to leave the choice of template engine to the final user.
The interface definition could be as simple as:
interface HTML_Template {
public abstract setTemplate($template, $templateOptions = null);
public abstract render($data = null);
}
Of course one may say, it's up to the application to provide the proper implementation of the interface... But wouldn't fall into the PEAR raison d'etre to provide such interface definition??? Besides, what's the point of each application redefining the interface every time...
In a first step, all PEAR template engines would need to implement the interface, but without actually using the "implements" keyword to preserve PHP4 BC. Note that this shouldn't be thought as an abstraction layer to template engines.
The same interface could be used by other kind of content-generating packages... PDF, images, XML...
Do you think? To get that working the PEAR community has to endorse it and have the package maintainers implement the interface in their own packages.
-Philippe