/** * Constructs a TwigEnvironment object and stores cache and storage * internally. */ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { // @todo Pass as arguments from the DIC. $this->cache_object = \Drupal::cache(); // Ensure that twig.engine is loaded, given that it is needed to render a // template because functions like twig_drupal_escape_filter are called. require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine'; // Set twig path namespace for themes and modules. $namespaces = array(); foreach ($module_handler->getModuleList() as $name => $extension) { $namespaces[$name] = $extension->getPath(); } foreach ($theme_handler->listInfo() as $name => $extension) { $namespaces[$name] = $extension->getPath(); } foreach ($namespaces as $name => $path) { $templatesDirectory = $path . '/templates'; if (file_exists($templatesDirectory)) { $loader->addPath($templatesDirectory, $name); } } $this->templateClasses = array(); $this->stringLoader = new \Twig_Loader_String(); parent::__construct($loader, $options); }
/** * Add view path * * @param string $path * @param string $namespace * * @return \Bridge\Bundle\TwigBundle\TwigTemplating */ public function addPath($path, $namespace = \Twig_Loader_Filesystem::MAIN_NAMESPACE) { if ($this->loader instanceof \Twig_Loader_Filesystem) { if (is_dir($path)) { $this->loader->addPath($path, $namespace); } } return $this; }
/** * Retorna una instancia de la interfaz Twig_LoaderInterface. * * @return Twig_LoaderInterface */ public static function getLoader() { if (is_null(self::$loader)) { self::$loader = new Twig_Loader_Filesystem(self::$config['templates_dir']); if (!is_null(self::$config['namespaces']) && is_array(self::$config['namespaces'])) { foreach (self::$config['namespaces'] as $namespace => $dir) { self::$loader->addPath($dir, $namespace); } } } return self::$loader; }
/** * Constructs a TwigEnvironment object and stores cache and storage * internally. */ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { // @todo Pass as arguments from the DIC. $this->cache_object = \Drupal::cache(); // Set twig path namespace for themes and modules. $namespaces = array(); foreach ($module_handler->getModuleList() as $name => $extension) { $namespaces[$name] = $extension->getPath(); } foreach ($theme_handler->listInfo() as $name => $extension) { $namespaces[$name] = $extension->getPath(); } foreach ($namespaces as $name => $path) { $templatesDirectory = $path . '/templates'; if (file_exists($templatesDirectory)) { $loader->addPath($templatesDirectory, $name); } } $this->templateClasses = array(); parent::__construct($loader, $options); }
/** * Adds a folder to the loader. * * @param $folder */ public function addFolder($folder) { $this->loader->addPath($folder); }
public function addBasePath($path, $classPrefix = 'Zend_View') { $this->loader->addPath($path); }