Template_PHPLIB : question about blocks ...
| From: | Laurent GLOCK | Date: | Wed, 21 May 2003 08:35:08 +0000 |
| Subject: | Template_PHPLIB : question about blocks ... | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-5495@lists.php.net to get a copy of this message | ||
Hi,
I'm using Template_PHPLIB, and I wonder how I can NOT RENDER an entire
bloc in a template.
Exemple :
---------
consider this template :
<!-- BEGIN item -->
Current value : {CURRENT_VAL} <br>
<!-- END item -->
One can use it with this code to display a list of values :
// Definition of block "item"
$oTpl->setBlock("template", "item", "curitem");
for ($i=0; $i < 3; $i++) {
// Setting current value
$oTpl->setVar("CURRENT_VAL", $i);
// parsing current bloc
$oTpl->parse("curitem", "item", true);
}
// Final parsing
$oTpl->parse("out", "template", true);
And here is the result :
Current Value : 0
Current Value : 1
Current Value : 2
When I have no value to display, the system is still displaying "Current
Value : ". How can I prevent it ? In other words, I can display a bloc 1
time or more, but I can't do it 0 times (I don't know how to replace
"<!-- BEGIN bloc --> ... <!-- END bloc -->" by nothing or in the
rendered template).
Does anyone know how I can do ?
Laurent
PS : a solution could be the following :
modification of the template :
<!-- BEGIN item -->
{CURRENT_LINE}
<!-- END item -->
generation of the HTML for {CURRENT_LINE} using another template :
Current value : {CURRENT_VAL} <br>
but I would prefer not to multiply so much the number of myu template
files...