boolean addBlock(
string
$placeholder, string
$blockname, string
$template)
|
|
Adds a block to the template changing a variable placeholder to a block placeholder.
Add means "replace a variable placeholder by a new block". This is different to PHPLibs templates. The function loads a block, creates a handle for it and assigns it to a certain variable placeholder. To to the same with PHPLibs templates you would call set_file() to create the handle and parse() to assign the parsed block to a variable. By this PHPLibs templates assume that you tend to assign a block to more than one one placeholder. To assign a parsed block to more than only the placeholder you specify in this function you have to use a combination of getBlock() and setVariable().
As no updates to cached data is necessary addBlock() and addBlockfile() are rather "cheap" meaning quick operations.
The block content must not start with <!-- BEGIN blockname --> and end with <!-- END blockname --> this would cause overhead and produce an error.
Parameters:
boolean replaceBlock(
string
$block, string
$template, [boolean
$keep_content = false])
|
|
Replaces an existing block with new content.
This function will replace a block of the template and all blocks contained in the replaced block and add a new block insted, means you can dynamically change your template.
Note that changing the template structure violates one of the IT[X] development goals. I've tried to write a simple to use template engine supporting blocks. In contrast to other systems IT[X] analyses the way you've nested blocks and knows which block belongs into another block. The nesting information helps to make the API short and simple. Replacing blocks does not only mean that IT[X] has to update the nesting information (relatively time consumpting task) but you have to make sure that you do not get confused due to the template change itself.
Parameters:
boolean setCallbackFunction(
string
$tplfunction, string
$callbackfunction, [string
$callbackobject = ''], [boolean
$expandCallbackParameters = false])
|
|
Sets a callback function.
IT[X] templates (note the X) can contain simple function calls. "function call" means that the editor of the template can add special placeholder to the template like 'func_h1("embedded in h1")'. IT[X] will grab this function calls and allow you to define a callback function for them.
This is an absolutely evil feature. If your application makes heavy use of such callbacks and you're even implementing if-then etc. on the level of a template engine you're reiventing the wheel... - that's actually how PHP came into life. Anyway, sometimes it's handy.
Consider also using XML/XSLT or native PHP. And please do not push IT[X] any further into this direction of adding logics to the template engine.
For those of you ready for the X in IT[X]:
<?php ... function h_one($args) { return sprintf('<h1>%s</h1>', $args[0]); }
... $itx = new HTML_Template_ITX(...); ... $itx->setCallbackFunction('h1', 'h_one'); $itx->performCallback(); ?>
template: func_h1('H1 Headline');
Parameters: