RE: Template system in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2008-02-14 at 08:58 +0400, Xavier de Lapeyre wrote:
> Sounds interesting...
> Are your XML predefined or generated on the run? From say a DB?

>From a compiler script that extends a base tag class... all it needs to
do is register the tag namespace, tag name, and the function that will
handle the tag's content. Here's a very simple case:

<?php

class ExampleSiteCompilersExampleSiteTag extends JinnBaseTagCompiler
{
    var $filename = __FILE__;
    
    function ___jinnConstruct()
    {
        $this->handlers = array
        (
            'example' => array
            (                 
                'mandatory' => 'expandTagMandatory',
            ),                              
        );    
    }     

    function expandTagMandatory
    ( &$content, &$space, &$tag, &$atts, &$tagStack )
    {
        return '<span class="mandatory">*</span>';
    }
}

?>

Then when doing forms I can do the following:

    <example:mandatory/>

And that will be expanded to:

    <span class="mandatory">*</span>

Then later down the road if I wanted the mandatory symbol to change to
an image, I could change the content expanded in the handler, rebuild
the site and all uses of the mandatory tag would be updated and would
incur no run-time overhead.

This is obviously a trivial example. There is much more that can be done.
For instance creating boxes, popups, relocating content, checking links,
image analysis to get the width and height of image at compile time instead
of run-time, etc. Encapsulating the data into a tag allows greatly
simplifying content. Also the tag system allows recursive expansion. So
a tag handler can output custom tags and those in turn will be expanded.
Hell, I could even create a validation tag around the primary layout
template that would then validate the content at build time.

Anyways, there ARE better template systems than PHP itself.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux