/** * 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; }
/** * Create node to be injected into template at place of tag caused import. * * @return Node */ public function createNode() { //Content of node to be imported $node = $this->supervisor->createNode($this->path, $this->token); //Let's register user defined blocks (context and attributes) as placeholders $node->mountBlock(self::CONTEXT_BLOCK, [], [$this->createPlaceholder(self::CONTEXT_BLOCK, $contextID)], true); foreach ($this->token[HtmlTokenizer::TOKEN_ATTRIBUTES] as $attribute => $value) { //Attributes counted as blocks to replace elements in included node $node->mountBlock($attribute, [], [$value], true); } //We now have to compile node content to pass it's body to parent node $content = $node->compile($dynamic); //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. Stempler to decide. foreach ($this->supervisor->syntax()->blockExporters() as $exporter) { $content = $exporter->mountBlocks($content, $dynamic); } //Let's parse complied content without any imports (to prevent collision) $supervisor = clone $this->supervisor; $supervisor->flushImporters(); //Outer content must be protected using unique names $rebuilt = new Node($supervisor, $supervisor->uniquePlaceholder(), $content); if (!empty($contextBlock = $rebuilt->findNode($contextID))) { //Now we can mount our content block $contextBlock->mountNode($this->contextNode()); } return $rebuilt; }