Example #1
0
 /**
  * Gernerate block for the passed node
  * 
  * @param SimpleXMLElement $node
  * @param SimpleXMLElement $parent
  * @return Core_Model_Layout 
  */
 protected function _generateBlock($node, $parent)
 {
     if (!empty($node['class'])) {
         $className = (string) $node['class'];
     } else {
         $className = App_Main::getBlockClassName((string) $node['type']);
     }
     $blockName = (string) $node['name'];
     $block = $this->addBlock($className, $blockName);
     if (!$block) {
         return $this;
     }
     if (!empty($node['parent'])) {
         $parentBlock = $this->getBlock((string) $node['parent']);
     } else {
         $parentName = $parent->getBlockName();
         if (!empty($parentName)) {
             $parentBlock = $this->getBlock($parentName);
         }
     }
     if (!empty($parentBlock)) {
         $alias = isset($node['as']) ? (string) $node['as'] : '';
         if (isset($node['before'])) {
             $sibling = (string) $node['before'];
             if ('-' === $sibling) {
                 $sibling = '';
             }
             $parentBlock->insert($block, $sibling, false, $alias);
         } elseif (isset($node['after'])) {
             $sibling = (string) $node['after'];
             if ('-' === $sibling) {
                 $sibling = '';
             }
             $parentBlock->insert($block, $sibling, true, $alias);
         } else {
             $parentBlock->append($block, $alias);
         }
     }
     if (!empty($node['template'])) {
         $block->setTemplate((string) $node['template']);
     }
     if (!empty($node['output'])) {
         $method = (string) $node['output'];
         $this->addOutputBlock($blockName, $method);
     }
     return $this;
 }