Hey,
Well this is what I have so far... It's not working of course, but it's my first idea of how I think it should work. The problem with this is that I'm trying to access instances that aren't there. Note that all of my "template variable knowing" handlers (TemplateDataFilter) have access to the main template/datasource class: $this->template. The template class has a variable called output. It's a class that contains an array in which the content of each handler pushes onto (a buffer chain).
Matt
ps, is this what you mean? The php handler code or the template syntax?
PHP Code:
class TemplateTagHandler extends TemplateDataFilter{
var $setHandler;
var $subTemplate;
function setSetTagHandler(&$h){
$this->setHandler =& $h;
}
function open(&$parser, &$name, &$attrs, &$empty){
if($name =='template'){
$subTemplate =& new Template($attrs['file']);
$subTemplate->_parent =& isset($this->subTemplate) ? $this->subTemplate : $this->template;
$this->subTemplate =& $subTemplate;
}
if($this->subTemplate || $name=='template'){
unset($name, $attrs, $empty);
}
parent::open($parser, $name, $attrs, $empty);
}
function data(&$parser, & $data){
if($this->subTemplate){
$data = NULL;
}
parent::data($parser, $data);
}
function close(&$parser, & $name, & $empty){
if($name=='template'){
$template =& $this->subTemplate;
if(is_object($template->_parent)){
$handler =& $template->_parent->_baseHandler;
while($next =& $handler->getNextHandler()){
if(strtolower(get_class($next)) == 'settaghandler'){
$tag = $next->current_tag;
$template->_parent->set($tag, $template->toString());
break;
}
$handler =& $next;
unset($next);
}
}else{
$this->template->output->write($template->toString());
}
unset($this->subTemplate);
}
if($name=='template' || $this->subTemplate){
unset($name, $empty);
}
parent::close($parser, $name, $empty);
}
}
Bookmarks