View Single Post
Old 11-06-2008, 01:51 PM   #7 (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

Hi Runar,

this is done via Macros.

Lets say you have one file (macros.html) containing your header, footer, etc. containing this code:

HTML Code:
<div metal:define-macro="header">
    Your header here
</div>

<div metal:define-macro="footer">
    Your footer here
</div>
In your HTML page you just write
HTML Code:
<div metal:use-macro="macros.html/header" />
and
HTML Code:
<div metal:use-macro="macros.html/footer" />
where you want them to be.

Way better is to use slots:
Lets say you have one template for all your pages (template.html):

HTML Code:
<html metal:define-macro="page_template">
   <head></head>
   <body>
        <tal:block metal:define-slot="content" />
   </body>
</html>
Create another file (page.html):
HTML Code:
<tal:block metal:use-macro="template.html/page_template">
    <tal:block metal:fill-slot="content">
        Your static Content here
        ${dynamic_content}
        or
        <span tal:content="another_dynamic_content" />
    </tal:block>
</tal:block>
To render this just call

PHP Code:
$phptal = new PHPTAL();
$phptal->setSource('page.html');
$phptal->dynamic_content 'something';
$phptal->another_dynamic_content 'something else';

echo 
$phptal->execute(); 
That's all. Btw. you can define and fill more than one slot...

You should also read the manual for PHPTAL on PHPTAL :: Template Attribute Language for PHP

Greetings,

Alex

Last edited by awuehr : 11-06-2008 at 04:14 PM.
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
The Following User Says Thank You to awuehr For This Useful Post:
Runar (11-06-2008)