[PHPTAL] Include templates
Bob Black
bblack-phptal at schlitzed.com
Sun Jun 10 23:28:47 CEST 2007
On Sun, Jun 10, 2007 at 08:51:06PM +0200, [BuKoX] wrote:
> Joshua Paine pisze:
> >You can do this:
> >
> ><metal:block define-macro="mymacro">
> >some text with <b>something bold</b>
> ></metal:block>
> Ok. But my structure of my site is different. I have header.html:
> and footer.html:
>
> I recieve exception in header.html that "Reached document end but
> element stack not empty in:27" - last line in header.html. It's strange
> becouse in Smarty it was very handy - I could include every template in
> every place independent of template structure.
> How can include templates in this way?
You need to think about TAL a little differently than say html
or php includes. (You can't "include" snippets of html, each
template file needs to be a complete document, tags have to
be matched, etc.)
Basically what I do is make a site wide wrap.xml document that looks
something like this.
------sample wrap-----
<html>
<head>
[...]
</head>
<body>
<div id='header'>
<!--- header html -->
</div>
<div id='content' tal:content='structure: page_content' />
<div id='header'>
<!--- header html -->
</div>
</body>
</html>
------end sample wrap-----
(Note "structure:", otherwise html tags in the 'page specific' body
be escaped.)
Then for each individual page I setup and execute() the page specific
template, and set it as $wrap->page_content. (Actually done in a site
wide php file included as the last step of each page.)
Hope that helps.
Bob Black
More information about the PHPTAL
mailing list