View Single Post
Old 01-08-2009, 05:50 AM   #23 (permalink)
awuehr
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

First of all you can define as much templates in one file, as you want. This file only has to be valid XML.

HTML Code:
<html>
    <head>...</head>
    <body>
        <tal:block condition="submitted">...show results...</tal:block>
        <tal:block condition="not:submitted">...show form</tal:block>
    </body>
</html>
is ok, but you even could write
HTML Code:
<tal:block>
    <html tal:condition="submitted">
        <head>...</head>
        <body>
            ...show results...
        </body>
    </html>
    <html tal:condition="not:submitted">
        <head>...</head>
        <body>
            ...show form...
        </body>
    </html>
</tal:block>
I'd prefer to define macros and use them, when they are required:

HTML Code:
<html>
    <head>...</head>
    <body>
        <tal:block metal:define-macro="submit">...show results...</tal:block>
        <tal:block metal:define-macro="form">...show form...</tal:block>
        <tal:block metal:use-macro="${action}" />
    </body>
</html>
In PHP you would write:
PHP Code:
$tal = new PHPTAL(<template.file>);
$tal->action = (isset($_REQUEST['submit']))?'submit':'form';
// define some other TAL variables to display...
echo $tal->execute(); 
If you use macros, you can put them to an external file and reuse them in other templates.

Another way would be to use slots.

About the 3d-array-problem:
Until now I did not find a way to do this in PHPTAL, there is no way to exit a loop when a condition (cols == x) becomes true or whatever.

How would you do this in patTemplate (which I don't know until now)?
__________________
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote