Template Sigma: 2 issues
| From: | Markus Ernst | Date: | Tue, 02 Aug 2005 19:41:02 +0000 |
| Subject: | Template Sigma: 2 issues | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-20234@lists.php.net to get a copy of this message | ||
Hello
Implementing Template Sigma (which I start to like very much!) in an
application I came across 2 issues:
1. Template caching strips whitespace out of output.
When working without template caching, this part of a template:
<!-- BEGIN thumbs -->
<a href="{href}"><img src="{pic}"></a>
<!-- END thumbs -->
produces for example this result (including whitespace):
<a href="page1.html"><img src="thumb1.jpg"></a>
<a href="page2.html"><img src="thumb2.jpg"></a>
When working with cached templates the output will be changed to:
<a href="page1.html"><img src="thumb1.jpg"></a><a
href="page2.html"><img
src="thumb2.jpg"></a>
which is definitely not the same, as lines of inline elements will not be
wrapped. Is this a bug? I don't mind if whitespace is stripped, but a line
break or at least one space should be there.
2. Replaced blocks are not displayed unless a variable is set.
I assume this is an expected behaviour; anyway it would be nice to have a
method for replacing a block with text that does not have to be parsed. This
would be useful in combination with caching: If there is cached content,
output this one - else process block. As a workaround I added a variable to
set. In the example $tpl is the template object, $cache the cache object:
if ($cache_content = $cache->start($cache_id)) {
if ($tpl->blockExists("thumbs")) {
$tpl->replaceBlock("thumbs", $cache_content);
$tpl->setVariable("parse", "");
$tpl->parse("thumbs");
}
}
else {
foreach ($pages as $page) {
$tpl->setCurrentBlock("thumbs");
$tpl->setVariable("href", $page['href']);
$tpl->setVariable("pic", $page['pic']);
$tpl->parseCurrentBlock();
}
$cache->save($cache_id, $tpl->get("thumbs")."{parse}");
}
Could this be done easier?
--
Markus