Now that we have introduced taglibs, two words need to be said about document generation.
When a tag is expanded it can output XHTML and/or PHP code. Therefore document generation is actually a two-step process: the starting point is a document containing tags and XHTML, this document is processed by the taglibs engine to produce a page that contains the XHTML from the original document and the result of tags expansion, which again is XHTML plus PHP code. The final XHTML/PHP page is evaluated as normal PHP script.
It's now clear that with respect to a traditional PHP script there is one more processing phase. Fortunately the taglibs engine is smart enough to cache documents after they have been processed: this means that taglibs processing only occurs once after the document has changed.

Although we suggest to choose a single approach for the implementation of widgets, it is always possible to use PHP and taglibs in the same widget file.
It must be pointed out that, as shown in the diagram below, PHP code is evaluated before taglibs, so it is possible to generate taglib code from PHP code.
