Re: [Phplib-users] dumping vars in a block
Brought to you by:
nhruby,
richardarcher
|
From: Layne W. <la...@if...> - 2001-08-14 14:11:16
|
> forgot to say, that I only wanna set address2 if it exists
>
> if ($q->f("address1")) {
> $tpl->set_var("address2",$q->f("address1")."<br>";
> } eles {
> $tpl->set_var("address1","");
> }
For what it is worth, I have extended my template class with a clear_var()
function (below). After parsing each loop, I call clear_var() with the
varname(s) that may be blank. For instance:
while($db->next_record()) {
$tpl->set_var("some_var", $db->f("some_var"));
if($db->f("optional_var")) $tpl->set_var("optional_var",
$db->f("optional_var"));
$tpl->parse("some_block", "some_loop", true);
$tpl->clear_var("optional_var");
}
I really appreciate it on large blocks with several optional variables.
Here's my function:
/* public: clear_var(array $varnames)
* varnames: array of variable names to be cleared
*
* public: clear_var(string $varname)
* varname: name of a variable that is to be cleared
*/
function clear_var($varname) {
if(is_array($varname)) {
while(list(,$value) = each($varname)) {
$this->set_var($value, "");
}
} else {
$this->set_var($varname, "");
}
}
Layne Weathers
Ifworld Inc
|