/** * merge all included templates into this one * @return PhtmlNode */ public function resolve() { if ($this->resolved) return $this; $this->resolved = true; $includeTags = array('p:render:template','p:include:file'); foreach($includeTags as $tagName) { list($ns,$tag,$attr) = explode(':',$tagName); $includeNodes = $this->getElementsByTagNameNS($ns,$tag); foreach($includeNodes as $renderNode) { $template = $renderNode->getAttribute($attr); $children = $renderNode->getChildren(); $view = new View($template); $innerTree = $view->getNodeTree(); //echo "\nFOUND:$template\n"; if (count($children) > 0) { $bodyNodes = $innerTree->getElementsByTagNameNS('p','body'); foreach($bodyNodes as &$bodyNode) { $parent = $bodyNode->getParent(); $ix = $bodyNode->getIndex(); //echo "\nFOuND BODY AT $ix: Children: ".count($children).chr(10); //print_r($children); $parent->addChildrenAt($ix, $children); $bodyNode->detach(); break; } } $parent = $renderNode->getParent(); //echo "\nPARENT TAG: {$parent->getTag()} : ".count($parent->getChildren())."\n"; $ix = $renderNode->getIndex(); //echo "\nRENDER IX: $ix : {$innerTree->getTag()} : ".count($innerTree->getChildren())."\n"; $parent->addChildrenAt($ix,$innerTree->getChildren()); $renderNode->detach(); //echo "\nPARENT TAG: {$parent->getTag()} : ".count($parent->getChildren())."\n"; } } return $this; }