/**
  * Renders a partial.
  *
  * @param string $partialName
  * @param string $sectionName
  * @param array $variables
  * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string
  * @return string
  */
 public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = FALSE)
 {
     if (!isset($this->partialIdentifierCache[$partialName])) {
         $this->partialIdentifierCache[$partialName] = $this->baseRenderingContext->getTemplatePaths()->getPartialIdentifier($partialName);
     }
     $partialIdentifier = $this->partialIdentifierCache[$partialName];
     $parsedPartial = $this->baseRenderingContext->getTemplateParser()->getOrParseAndStoreTemplate($partialIdentifier, function ($parent, TemplatePaths $paths) use($partialName) {
         return $paths->getPartialSource($partialName);
     });
     $renderingContext = clone $this->getCurrentRenderingContext();
     $renderingContext->setVariableProvider($renderingContext->getVariableProvider()->getScopeCopy($variables));
     $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
     if ($sectionName !== NULL) {
         $output = $this->renderSection($sectionName, $variables, $ignoreUnknown);
     } else {
         $output = $parsedPartial->render($renderingContext);
     }
     $this->stopRendering();
     return $output;
 }
Beispiel #2
0
 /**
  * @param string $templateIdentifier
  * @param \Closure $templateSourceClosure Closure which returns the template source if needed
  * @return ParsedTemplateInterface
  */
 public function getOrParseAndStoreTemplate($templateIdentifier, $templateSourceClosure)
 {
     $compiler = $this->renderingContext->getTemplateCompiler();
     if (isset($this->parsedTemplates[$templateIdentifier])) {
         $parsedTemplate = $this->parsedTemplates[$templateIdentifier];
     } elseif ($compiler->has($templateIdentifier)) {
         $parsedTemplate = $compiler->get($templateIdentifier);
     } else {
         $parsedTemplate = $this->parse($templateSourceClosure($this, $this->renderingContext->getTemplatePaths()), $templateIdentifier);
         $this->parsedTemplates[$templateIdentifier] = $parsedTemplate;
         if ($parsedTemplate->isCompilable()) {
             try {
                 $compiler->store($templateIdentifier, $parsedTemplate);
             } catch (StopCompilingException $stop) {
                 $parsedTemplate->setCompilable(FALSE);
                 return $parsedTemplate;
             }
         }
     }
     return $parsedTemplate;
 }
Beispiel #3
0
 /**
  * Renders a partial.
  *
  * @param string $partialName
  * @param string $sectionName
  * @param array $variables
  * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string
  * @return string
  */
 public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = false)
 {
     $templatePaths = $this->baseRenderingContext->getTemplatePaths();
     try {
         $parsedPartial = $this->baseRenderingContext->getTemplateParser()->getOrParseAndStoreTemplate($templatePaths->getPartialIdentifier($partialName), function ($parent, TemplatePaths $paths) use($partialName) {
             return $paths->getPartialSource($partialName);
         });
     } catch (PassthroughSourceException $error) {
         return $error->getSource();
     }
     $renderingContext = clone $this->getCurrentRenderingContext();
     $renderingContext->setVariableProvider($renderingContext->getVariableProvider()->getScopeCopy($variables));
     $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
     if ($sectionName !== null) {
         $output = $this->renderSection($sectionName, $variables, $ignoreUnknown);
     } else {
         $output = $parsedPartial->render($renderingContext);
     }
     $this->stopRendering();
     return $output;
 }
Beispiel #4
0
 /**
  * Warm up _layoutRootPaths_ of the provided RenderingContext's
  * TemplatePaths instance. Simple, recursive processing of all
  * supported format template files in path(s), compiling only
  * the topmost (override) template file if the same template
  * exists in multiple layout root paths.
  *
  * Like other methods, returns a FluidCacheWarmupResult instance
  * which can be merged with other result instances.
  *
  * @param RenderingContextInterface $renderingContext
  * @return FluidCacheWarmupResult
  */
 protected function warmupLayoutRootPaths(RenderingContextInterface $renderingContext)
 {
     $result = new FluidCacheWarmupResult();
     $paths = $renderingContext->getTemplatePaths();
     foreach ($this->formats as $format) {
         foreach ($paths->resolveAvailableLayoutFiles($format) as $layoutFile) {
             $paths->setFormat($format);
             $state = $this->warmSingleFile($layoutFile, $paths->getLayoutIdentifier(basename($layoutFile, '.' . $layoutFile)), $renderingContext);
             $result->add($state, $layoutFile);
         }
     }
     return $result;
 }