RE: [Phplib-users] phplib templates blocks
Brought to you by:
nhruby,
richardarcher
|
From: Layne W. <la...@if...> - 2002-05-17 14:15:01
|
> I don't want the html inside the blocks to print if the block
> is undefiened.
> For example:
>
> <!-- BEGIN TheBlock -->
> I don't want this text to show if the block "TheBlock" is undefiened.
> <!-- END TheBlock -->
>
> Do i need to hack the set_block method?
> Has anyone else already done this?
The Template class is designed for substituting text, not handling logic.
Asking Template to search all variables for valid blocks and then remove
them is going to be _extremely_ inefficient. Instead, when you have multiple
possible blocks where only one block will show, do _not_ set the block that
will show - set and clear the unused block(s).
----- search_results.tpl -----
<h1>Search Results</h1>
<!-- BEGIN list -->
<table>
<!-- BEGIN row -->
<tr>
<td>{some_data}</td>
</tr>
<!-- END row -->
</table>
<!-- END list -->
<!-- BEGIN no_list -->
<p>No items matched your query.</p>
<!-- END no_list -->
----- search_results.php -----
$t = new Template;
$t->set_file("results", "search_results.tpl");
// do a query here
if(count($results)) {
$t->set_block("results", "row", "rows");
// build the list here
$t->set_block("results", "no_list");
$t->set_var("no_list", "");
} else {
$t->set_block("results", "list");
$t->set_var("list", "");
}
-----
Layne Weathers
Ifworld Inc.
|