Re: Re: Templating engines

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

 



On Sun, 2005-07-03 at 03:24, Burhan Khalid wrote:
> Robert Cummings wrote:
> > On Fri, 2005-04-29 at 23:55, Rasmus Lerdorf wrote:
> > 
> > [--SNIPPED--]
> > 
> > This isn't a problem for engines that compile to PHP source that has
> > direct hooks into the necessary data structures that will contain the
> > data at run time.
> > 
> > Smarty isn't one of them though :)
> 
> Hey Robert -- can you give an example of one that does this? I'm just 
> curious as I haven't seen many that do this.

InterJinn's TemplateJinn :)

The following is an example login template:

----------------------------------------------------------------------
<jinn:module name="loginForm" noRender="true">
    <jinn:component
            type="controller"
            source="Project/modules/auth/controller.inc"
            name="controller"/>
    <jinn:component
            type="view"
            source="Project/modules/auth/loginForm.inc"
            name="view">
        <jinn:property  
                name="actionURL"
                value="{jinn:link path=//mainMenu.phtml}"/>           
    </jinn:component>
</jinn:module>

<table border="0" cellspacing="0" cellpadding="5">
<jinn:render name="loginForm" selector="formOpen"/>
<tr>
    <td align="right"><b>Login:</b></td>
    <td><jinn:render name="loginForm" selector="userWidget"/></td>
</tr>
<tr>
    <td align="right"><b>Password:</b></td>
    <td><jinn:render name="loginForm" selector="passwordWidget"/></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><jinn:render name="loginForm" selector="submitWidget"/></td>
</tr>
<jinn:render name="loginForm" selector="formClose"/>
</table>
----------------------------------------------------------------------

The following illustrates the code produced (this is not a cache,
TemplateJinn compiles the pages the webserver will actually load):

----------------------------------------------------------------------
<?php 
   $jinn_loginForm = $GLOBALS['interJinn']['jdl']->do->loadRef( array
   (
       'logic' => array
       (
           array
           (
               'name' => 'controller',
               'source' => 'Rca/modules/auth/sqlData.inc',
           ),
       ),
       'render' => array
       (
           array
           (
               'name' => 'view',
               'source' => 'Rca/modules/auth/loginForm.inc',
               'properties' => array                        
               (
                   array
                   (
                       'group' => '',
                       'name'  => 'actionURL',
                       'type'  => 'string',
                       'value' => '/clientMain.phtml',
                   ),                                    
               ),    
           ),
       ),
   ) );  
 ?>
<table border="0" cellspacing="0" cellpadding="5">
<?php 
   $jinn_loginForm->render( 'formOpen' );
 ?>
<tr>
    <td align="right"><b>Login:</b></td>
    <td><?php 
   $jinn_loginForm->render( 'userWidget' );
 ?></td>
</tr>   
<tr>    
    <td align="right"><b>Password:</b></td>
    <td><?php 
   $jinn_loginForm->render( 'passwordWidget' );
 ?></td>
</tr>   
<tr>    
    <td>&nbsp;</td>
    <td><?php 
   $jinn_loginForm->render( 'submitWidget' );
 ?></td>
</tr>   
<?php   
   $jinn_loginForm->render( 'formClose' );
 ?>
</table>
----------------------------------------------------------------------

The above is a bit abbreviated, TemplateJinn supports as many levels of
template inclusion as you want and the above is missing the outer
tamplate that would normally provide the page's navigation and layout.
Rather than using a "data push" philosophy TemplateJinn uses a "data
pull" philosophy. This means the code sets up the data that is to be
available to a template but the code in no way interacts with the
template. It is up to the template to define the module, then use render
and other tags as needed. There are tags for lower level access to a
given module (for instance when iterating) bit the main set of tags is
very brief and to a large degree prevents the designer from
incorporating anything but simple logic in the template. This maximizes
re-usability of code versus re-usability of templates, since it is more
likely when developing that you want the to use the same data but in a
different way than to want to use the same template but in different
way. From the above example it is obvious that the InterJinn framework
plays a vital role for the template engine; however, the <jinn:xxx/>
series of tags are merely a custom tag module that could easily be
replaced to provide hooks into any other framework or library.
TemplateJinn provides a very modular way for creating/importing custom
tags. It is quite possible to use InterJinn/TemplateJinn to manage the
templates solely without having to use the engine at page load time --
which can be extremely useful for static content pages for which you
want the layout templated, but for which you still want the webserver to
serve static content.

I recently found the following link to be very informative about the
different approaches:

    http://www.phpwact.org/pattern/template_view

Personally I've never liked the Smarty system because it uses the push
philosophy and IMHO the code should never couple itself to a template,
at least not as far as web page development is concerned. The code
loading a template is more suited to email markup and such things than
for page markup-- but that's not to say that TemplateJinn is unable to
do nice email templates :) That said, Smarty is light years better than
the eztemplate system that I've had the displeasure of working with
(although maybe it improved with the latest version).

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