new feature for IT
| From: | Alexander Merz | Date: | Tue, 11 Dec 2001 01:48:59 +0000 |
| Subject: | new feature for IT | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-3432@lists.php.net to get a copy of this message | ||
I add a new feature for IntegratedTemplate.
The idea is by Kristian Koehntopp, he noted it on the PHP-Dev-Mailinglist:
"I suggest you remove this. The template itself shall contain
the information which characters are being used as delimters.
Proper processing of a template shall not be dependent on
information outside of the template."
Short: The designer knows which char or expression can be used to markup
variables and blocks, so the designer should set them.
So, i add the it_set-feature to IT
Template-Example tpl.html:
--------
<?it_set
delimiter_var_start !
delimiter_var_end !
delimiter_block_start <BLOCK %>
delimiter_block_end </BLOCK %>
remove_unknown_vars 1
remove_empty_blocks 1
?>
<html>
<head>!TITLE!</head>
<body>
<table>
<BLOCK tab>
<tr>
<td>!CELL!</td>
</tr>
</BLOCK tab>
</table>
</body>
</html>
----------
Program-Example
----------
<?php
include("HTML/IT.php") ;
$it = new IntegratedTemplate("./", true) ;
$it -> loadTemplateFile("tpl.html") ;
$it -> setCurrentBlock('tab') ;
$it -> setVariable('CELL', "First Cell") ;
$it ->parseCurrentBlock('tab') ;
$it -> setVariable('CELL', "Second Cell") ;
$it ->parseCurrentBlock('so') ;
$it -> setCurrentBlock() ;
$it -> setVariable('TITLE', "title of this demo") ;
$it ->parseCurrentBlock() ;
$it -> show() ;
?>
----------
Take a look on the constructor, a second parameter is now supported, when the
parameter is true IT checks for a <?it_set ?>-section and analyse the commands.
When false, it didn't analyse the stuff, it only cut a section from a template.
I didn't commit this at the moment, because it requires a lot of rewrite of
early hardcoded regular expressions, which are now build while run time. So
this cause problems with existing programs using IT.
The changed IT.php is avaible from
http://www-user.tu-chemnitz.de/~meal/php/it.zip.
Please test it.
I would commit it to pear/IT instead of php4/pear/HTML/IT to markup a "new
generation" of IT and to start moving stuff from php4/pear to pear/
Cu, Alex