Symfony\Bundle\TwigBundle\Loader\FilesystemLoader::findTemplate PHP Method

findTemplate() protected method

The file locator is used to locate the template when the naming convention is the symfony one (i.e. the name can be parsed). Otherwise the template is located using the locator from the twig library.
protected findTemplate ( string | Symfony\Component\Templating\TemplateReferenceInterface $template, boolean $throw = true ) : string
$template string | Symfony\Component\Templating\TemplateReferenceInterface The template
$throw boolean When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
return string The path to the template file
    protected function findTemplate($template, $throw = true)
    {
        $logicalName = (string) $template;
        if (isset($this->cache[$logicalName])) {
            return $this->cache[$logicalName];
        }
        $file = null;
        $previous = null;
        try {
            $file = parent::findTemplate($logicalName);
        } catch (\Twig_Error_Loader $e) {
            $twigLoaderException = $e;
            // for BC
            try {
                $template = $this->parser->parse($template);
                $file = $this->locator->locate($template);
            } catch (\Exception $e) {
            }
        }
        if (false === $file || null === $file) {
            if ($throw) {
                throw $twigLoaderException;
            }
            return false;
        }
        return $this->cache[$logicalName] = $file;
    }

Usage Example

Esempio n. 1
0
 /**
  * @param string $template
  * @param bool $throw
  * @return string
  */
 protected function findTemplate($template, $throw = true)
 {
     $parts = explode(':', $template);
     $parts[1] = 'Content';
     $defaultTemplate = implode(':', $parts);
     return parent::findTemplate($defaultTemplate, $throw);
 }
All Usage Examples Of Symfony\Bundle\TwigBundle\Loader\FilesystemLoader::findTemplate