Example #1
0
 /**
  * {@inheritdoc}
  */
 public function createNode()
 {
     //We need node with content being importer
     $node = $this->templater->createNode($this->location, '', $this->token);
     //Let's register user defined blocks (context and attributes) as placeholders
     $node->registerBlock(self::CONTEXT_BLOCK, [], [$this->createPlaceholder(self::CONTEXT_BLOCK, $contextID)], true);
     foreach ($this->attributes as $attribute => $value) {
         //Attributes counted as blocks to replace elements in included node
         $node->registerBlock($attribute, [], [$value], true);
     }
     //We now have to compile node content to pass it's body to parent node
     $content = $node->compile($outerBlocks);
     //Outer blocks (usually user attributes) can be exported to template using non default
     //rendering technique, for example every "extra" attribute can be passed to specific
     //template location. Templater to decide.
     $content = $this->templater->exportBlocks($content, $outerBlocks);
     //Let's parse complied content without any imports (to prevent collision)
     $templater = clone $this->templater;
     $templater->flushImports();
     //Outer content must be protected using unique names
     $rebuilt = new Node($templater, $templater->uniquePlaceholder(), $content);
     if ($contextBlock = $rebuilt->findNode($contextID)) {
         //Now we can mount our content block
         $contextBlock->addNode($this->getContext());
     }
     return $rebuilt;
 }
Example #2
0
 /**
  * Replace node content with content provided by external node, external node can still use
  * content of parent block by defining block named identical to it's parent.
  *
  * @param Node $node
  */
 private function replaceNode(Node $node)
 {
     //Looking for parent block call
     if (!empty($inner = $node->findNode($this->name))) {
         //This construction allows child block use parent content
         $inner->nodes = $this->nodes;
     }
     $this->nodes = $node->nodes;
 }