예제 #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;
 }
예제 #2
0
 /**
  * Fetch imports from declared location.
  *
  * @param Templater $templater
  * @param mixed     $location
  * @param array     $token
  * @throws TemplaterException
  */
 protected function fetchImports(Templater $templater, $location, array $token)
 {
     //Let's create bundle node
     $bundle = $templater->createNode($location, '', $token);
     /**
      * We expecting to fetch imports located in templater associated with bundle node.
      *
      * @var Templater $bundleTemplater
      */
     $bundleTemplater = $bundle->getSupervisor();
     if (!$bundleTemplater instanceof Templater) {
         throw new TemplaterException("BundleImport must be executed using Templater.", $token);
     }
     //We can fetch all importers from our bundle view
     $this->imports = $bundleTemplater->getImports();
 }