Re: ITX multiple files example?
| From: | Bertrand Mansion | Date: | Mon, 05 Nov 2001 18:17:15 +0000 |
| Subject: | Re: ITX multiple files example? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-2562@lists.php.net to get a copy of this message | ||
le 5/11/01 18:06, Wolfram Kriesing à lists@kriesing.de a écrit :
>> i'm trying to figure out how to use separate template files as
>> blocks within the global template with ITX.
>
> i tried to figure that out too,
> i think there is no way
> you have to use a template-object for the block, parse it and put the
> content in a {spaceHolder}
> that's how i did it and it made me see that IT[X] needs to be
> extended or replaced
>
> are there plans to extend this or add a better Template-class to PEAR?
Hi,
You can do this by using the addBlockFile method of ITX.php
Just create two template files a main one and a secondary one.
Don't forget to put a template variable in your main template where your
secondary template is supposed to appear.
example :
main.html --------------------------
<html><body>
Hello {NAME}<br>
Here goes your second template :<br>{HEREITGOES}</body></html>
2.html ---------------------
This is my second template that I want to include in my first template.<br>
It can have a variable in there like this : {MYVAR}<br>
I am not sure it works if there is no var in there..?<br>
Then in your PHP code, just do :
<?php
require_once('HTML/ITX.php');
$tpl = new IntegratedTemplateExtension('.');
$tpl->loadTemplatefile('main.html');
$tpl->setVariable('NAME', 'world');
$tpl->addBlockFile('HEREITGOES', 'BLOCK_SECONDTPL', '2.html');
// It creates a new block called BLOCK_SECONDTPL in place
// of SECONDTPL which you can use as you want.
// For instance :
$tpl->setCurrentBlock('BLOCK_SECONDTPL');
$tpl->setVariable('MYVAR', 'This is my var.');
$tpl->parseCurrentBlock();
$tpl->show();
?>
Make sure you are using at least version 1.7 of ITX as previous ones were
buggy.
This should do the trick. I don't know if that's what you were after, but I
don't think ITX is that bad. Smarty is good for some operations though,
there are cases where you would want to use one and then the other.
It would be cool to have the same sort of API for both of them...
Bertrand Mansion
Mamasam