findTemplate example



    // Previously it was possible to access files in the parent directory of a     // namespace. This was removed in Twig 2.15.3. In order to support backwards     // compatibility, we are adding path directory as a namespace, and therefore     // we can remove the directory traversal from the name.     // @todo deprecate this functionality for removal in Drupal 11.     if (preg_match('/(^\@[^\/]+\/)\.\.\/(.*)/', $name$matches)) {
      $name = $matches[1] . $matches[2];
    }

    return parent::findTemplate($name$throw);
  }

}
$path .= DIRECTORY_SEPARATOR . 'help_topics';
    if (is_dir($path)) {
      $this->cache = $this->errorCache = [];
      $this->paths[self::MAIN_NAMESPACE][] = rtrim($path, '/\\');
    }
  }

  /** * {@inheritdoc} */
  public function getSourceContext(string $name): Source {
    $path = $this->findTemplate($name);

    $contents = file_get_contents($path);
    try {
      // Note: always use \Drupal\Core\Serialization\Yaml here instead of the       // "serializer.yaml" service. This allows the core serializer to utilize       // core related functionality which isn't available as the standalone       // component based serializer.       $front_matter = new FrontMatter($contents, Yaml::class);

      // Reconstruct the content if there is front matter data detected. Prepend       // the source with {% line \d+ %} to inform Twig that the source code

        $this->twig = $twig;
        $this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
        $this->debug = \is_bool($debug) ? $debug : $debug(...);
    }

    public function render(\Throwable $exception): FlattenException
    {
        $flattenException = FlattenException::createFromThrowable($exception);
        $debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($flattenException);

        if ($debug || !$template = $this->findTemplate($flattenException->getStatusCode())) {
            return $this->fallbackErrorRenderer->render($exception);
        }

        return $flattenException->setAsString($this->twig->render($template[
            'exception' => $flattenException,
            'status_code' => $flattenException->getStatusCode(),
            'status_text' => $flattenException->getStatusText(),
        ]));
    }

    public static function isDebug(RequestStack $requestStack, bool $debug): \Closure
    {
$path = rtrim($path, '/\\');

        if (!isset($this->paths[$namespace])) {
            $this->paths[$namespace][] = $path;
        } else {
            array_unshift($this->paths[$namespace]$path);
        }
    }

    public function getSourceContext(string $name): Source
    {
        if (null === $path = $this->findTemplate($name)) {
            return new Source('', $name, '');
        }

        return new Source(file_get_contents($path)$name$path);
    }

    public function getCacheKey(string $name): string
    {
        if (null === $path = $this->findTemplate($name)) {
            return '';
        }
        


    return NULL;
  }

  /** * {@inheritdoc} */
  public function getCacheKey(string $name): string {
    // The parent implementation does unnecessary work that triggers     // deprecations in PHP 8.1.     return $this->findTemplate($name) ?: '';
  }

}
Home | Imprint | This part of the site doesn't use cookies.