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
Beispiel #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);
 }
 protected function findTemplate($name, $throw = true)
 {
     // If it's prefixed with "Theme" we need to change the name before we pass it along...
     if (TwigDatabaseLoader::MAGIC_TEMPLATE === substr($name, 0, strlen(TwigDatabaseLoader::MAGIC_TEMPLATE))) {
         $name = $this->defaultLoadBundle . substr($name, strlen(TwigDatabaseLoader::MAGIC_TEMPLATE));
         return parent::findTemplate($name, $throw);
     }
     throw new Twig_Error_Loader(sprintf('Template for "%s" does not exist and is not prefixed.', $name));
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 protected function findTemplate($template)
 {
     $templateName = (string) $template;
     // Only try and load templates which aren't namespaced
     if (strpos($templateName, '@theme/') === 0) {
         $templatePath = str_replace('@theme', '', $templateName);
         $theme = $this->themeManager->getAdminTheme();
         return parent::findTemplate('@theme_' . $theme->getName() . $templatePath);
     }
     if (strpos($templateName, 'theme_') === 0) {
         if (preg_match('/theme_([^:]+):([^:]*):(.*)/', $templateName, $matches)) {
             list($fullName, $themeName, $path, $file) = $matches;
             $theme = $this->themeManager->getTheme($themeName);
             return parent::findTemplate('@theme_' . $theme->getName() . $path . '/' . $file);
         }
     }
     return parent::findTemplate($template);
 }
 /**
  * @param string|TemplateReferenceInterface $template
  * @return string
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     if ($this->request === null && $this->container->isScopeActive('request')) {
         $this->request = $this->container->get('request');
     }
     $locale = $this->request ? $this->request->attributes->get('_locale') : 'en';
     if (is_string($template)) {
         if (strpos($template, ':')) {
             try {
                 $template = $this->parser->parse($template);
             } catch (\Exception $e) {
             }
         } else {
             return parent::findTemplate($template);
         }
     }
     if ($locale !== 'en') {
         $params = $template->all();
         $localizedTemplate = new TemplateReference($params['bundle'], $params['controller'], $params['name'], $params['format'], $params['engine']);
         if ($params['controller']) {
             $localizedTemplate->set('controller', $locale . '/' . $params['controller']);
         } else {
             $localizedTemplate->set('name', $locale . '/' . $params['name']);
         }
         try {
             return parent::findTemplate($localizedTemplate);
         } catch (\Twig_Error_Loader $e) {
             return parent::findTemplate($template);
         }
     }
     return parent::findTemplate($template);
 }
 protected function findTemplate($template, $throw = true)
 {
     //todo: find formatPath Template first
     return parent::findTemplate($template, $throw);
 }
 protected function findTemplate($template)
 {
     $template = $this->frontSynchroniserManager !== null && $this->isFrontSynchroniserTemplate($template) ? $this->frontSynchroniserManager->compile($template) : $template;
     return parent::findTemplate($template);
 }