Template_IT: Displaying a welcome message and a status bar
| From: | Ryan Churches | Date: | Thu, 30 Aug 2007 19:36:40 +0000 |
| Subject: | Template_IT: Displaying a welcome message and a status bar | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-27863@lists.php.net to get a copy of this message | ||
I'm finding this very confusing. My first unattainable goal is to display a
simple welcome message when the program starts running:
The Template..
<html>
<!-- BEGIN main -->
<P>This program searches for item that are no longer in
stock. Use sparingly. This could take a while...</P>
<!-- END main -->
..and the code.
$template = new HTML_Template_IT("./templates");
$template->loadTemplatefile("stockcheck.tpl", true, true);
$template->touchBlock("main");
$template->show("main");
flush();
.. but this simply does not work. Nothing gets displayed ever. I can get it
to print the message if I modify the $template->show(); so that it does not
specify main, but then it will display a table further down the page in
another block where no data is assigned (but curiously, not the status block
I will talk about next).
Output with show("main"):
<NOTHNIG>
Output with show();
This program searches for items that are no longer in stock. Use sparingly.
This could take a while...
SKU
Title
End?
End
I'm also having problems figuring out how I'm supposed to create a simple
status message. The problem seems to be there is no way to clear a block
once data is assigned. For instance.
The template is as follows:
<!-- BEGIN status -->
<DIV>Checking inventory... {PERCENT}% complete.</DIV>
<!-- END status -->
..and my code wants to set, parse, show, and flush it through multiple
iterations of the loop.
do
{
<<Gets an object of results from an api call>>
$template->setCurrentBlock('status');
$template->setVariable("PERCENT", $request->Pagination->PageNumber * 100 /
$response->PaginationResult->TotalNumberOfPages);
$template->parse("status");
$template->show("status");
flush();
$request->Pagination->PageNumber++;
}
while ($response->HasMoreItems);
..the problem here is the contents of the block get aggregated, not
overwritten. So, on the first pass, the show() will display:
Checking inventory... 33.3333333333% complete.
..and on the second.
Checking inventory... 33.3333333333% complete.
Checking inventory... 66.6666666667% complete.
..and finally.
Checking inventory... 33.3333333333% complete.
Checking inventory... 66.6666666667% complete.
Checking inventory... 100% complete.
Is there any way to clear the block after every pass while still displaying
it?
Here is the entire template. The last block (data) with a table gets
displayed no problem as part of a loop in another function where the
template is loaded and parsed all over again:
<html>
<!-- BEGIN main -->
<P>This program searches for items that are no longer in
stock. Use sparingly. This could take a while...</P>
<!-- END main -->
<!-- BEGIN status -->
<DIV>Checking inventory... {PERCENT}% complete.</DIV>
<!-- END status -->
<form action="EndItem.php" method="POST">
<table border>
<th>
SKU
</th>
<th>
Title
</th>
<th>
End?
</th>
<!-- BEGIN data -->
<tr>
<td>
{SKU}
</td>
<td>
<a href="{URL}">
{Title}
</a>
</td>
<td>
<input name="endItems[]" value="{ItemID}" type="checkbox">
</input>
</td>
</tr>
<!-- END data -->
</table>
<input type="submit" value="End">
</form>
</html>
..perhaps Template_IT isn't really meant to do a status indicator like I'm
trying to do? Any help is much appreciated.