src/Template/TemplateUtil.php
public function getAllTemplates()
    {
        $strCacheDir = $this->container->getParameter('kernel.cache_dir');

        // Try to load from cache
        if (file_exists($strCacheDir.'/contao/config/twig-templates.php')) {
            self::$twigFiles = include $strCacheDir.'/contao/config/twig-templates.php';

            return self::$twigFiles;
        }

        $bundles = $this->kernel->getBundles();

        if (\is_array($bundles)) {
            foreach (array_reverse($bundles) as $key => $value) {
                $path = $this->kernel->locateResource("@$key");

                $dir = rtrim($path, '/').'/Resources/views';

                if (!is_dir($dir)) {
                    continue;
                }
                $finder = new Finder();
                $twigKey = preg_replace('/Bundle$/', '', $key);

                foreach ($finder->in($dir)->files()->name('*.twig') as $file) {
                    /** @var SplFileInfo $file */
                    $name = $file->getBasename();
                    $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

                    if (isset(self::$twigFiles[$name])) {
                        continue;
                    }

                    self::$twigFiles[$name] = "@$twigKey/".$file->getRelativePathname();

                    if ($legacyName !== $name) {
                        self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                    }
                }
            }
        }

        foreach ($this->container->get('contao.resource_finder')->findIn('templates')->name('*.twig') as $file) {
            $name = $file->getBasename();
            $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

            /* @var SplFileInfo $file */
            self::$twigFiles[$name] = $file->getRealPath();

            if ($legacyName !== $name) {
                self::$twigFiles[$legacyName] = self::$twigFiles[$name];
            }
        }

        // add root templates
        $rootTemplates = $this->findTemplates($this->containerUtil->getProjectDir().'/templates/');

        if (\is_array($rootTemplates)) {
            foreach ($rootTemplates as $file) {
                $name = basename($file);
                $legacyName = false !== strpos($name, 'html.twig') ? basename($file, '.html.twig') : $name;

                self::$twigFiles[$name] = $file;

                if ($legacyName !== $name) {
                    self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                }
            }
        }

        return self::$twigFiles;
    }
public function getAllTemplates()
    {
        $strCacheDir = $this->container->getParameter('kernel.cache_dir');

        // Try to load from cache
        if (file_exists($strCacheDir.'/contao/config/twig-templates.php')) {
            self::$twigFiles = include $strCacheDir.'/contao/config/twig-templates.php';

            return self::$twigFiles;
        }

        $bundles = $this->kernel->getBundles();

        if (\is_array($bundles)) {
            foreach (array_reverse($bundles) as $key => $value) {
                $path = $this->kernel->locateResource("@$key");

                $dir = rtrim($path, '/').'/Resources/views';

                if (!is_dir($dir)) {
                    continue;
                }
                $finder = new Finder();
                $twigKey = preg_replace('/Bundle$/', '', $key);

                foreach ($finder->in($dir)->files()->name('*.twig') as $file) {
                    /** @var SplFileInfo $file */
                    $name = $file->getBasename();
                    $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

                    if (isset(self::$twigFiles[$name])) {
                        continue;
                    }

                    self::$twigFiles[$name] = "@$twigKey/".$file->getRelativePathname();

                    if ($legacyName !== $name) {
                        self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                    }
                }
            }
        }

        foreach ($this->container->get('contao.resource_finder')->findIn('templates')->name('*.twig') as $file) {
            $name = $file->getBasename();
            $legacyName = false !== strpos($name, 'html.twig') ? $file->getBasename('.html.twig') : $name;

            /* @var SplFileInfo $file */
            self::$twigFiles[$name] = $file->getRealPath();

            if ($legacyName !== $name) {
                self::$twigFiles[$legacyName] = self::$twigFiles[$name];
            }
        }

        // add root templates
        $rootTemplates = $this->findTemplates($this->containerUtil->getProjectDir().'/templates/');

        if (\is_array($rootTemplates)) {
            foreach ($rootTemplates as $file) {
                $name = basename($file);
                $legacyName = false !== strpos($name, 'html.twig') ? basename($file, '.html.twig') : $name;

                self::$twigFiles[$name] = $file;

                if ($legacyName !== $name) {
                    self::$twigFiles[$legacyName] = self::$twigFiles[$name];
                }
            }
        }

        return self::$twigFiles;
    }
public function getAllTemplates ( ) { $ strCacheDir = $ this -> container -> getParameter ( 'kernel.cache_dir' ) ; // Try to load from cache if ( file_exists ( $ strCacheDir . '/contao/config/twig-templates.php' ) ) { self :: $ twigFiles = include $ strCacheDir . '/contao/config/twig-templates.php' ; return self :: $ twigFiles ; } $ bundles = $ this -> kernel -> getBundles ( ) ; if ( \ is_array ( $ bundles ) ) { foreach ( array_reverse ( $ bundles ) as $ key => $ value ) { $ path = $ this -> kernel -> locateResource ( "@$key" ) ; $ dir = rtrim ( $ path , '/' ) . '/Resources/views' ; if ( ! is_dir ( $ dir ) ) { continue ; } $ finder = new Finder ( ) ; $ twigKey = preg_replace ( '/Bundle$/' , '' , $ key ) ; foreach ( $ finder -> in ( $ dir ) -> files ( ) -> name ( '*.twig' ) as $ file ) { /** @var SplFileInfo $file */ $ name = $ file -> getBasename ( ) ; $ legacyName = false !== strpos ( $ name , 'html.twig' ) ? $ file -> getBasename ( '.html.twig' ) : $ name ; if ( isset ( self :: $ twigFiles [ $ name ] ) ) { continue ; } self :: $ twigFiles [ $ name ] = "@$twigKey/" . $ file -> getRelativePathname ( ) ; if ( $ legacyName !== $ name ) { self :: $ twigFiles [ $ legacyName ] = self :: $ twigFiles [ $ name ] ; } } } } foreach ( $ this -> container -> get ( 'contao.resource_finder' ) -> findIn ( 'templates' ) -> name ( '*.twig' ) as $ file ) { $ name = $ file -> getBasename ( ) ; $ legacyName = false !== strpos ( $ name , 'html.twig' ) ? $ file -> getBasename ( '.html.twig' ) : $ name ; /* @var SplFileInfo $file */ self :: $ twigFiles [ $ name ] = $ file -> getRealPath ( ) ; if ( $ legacyName !== $ name ) { self :: $ twigFiles [ $ legacyName ] = self :: $ twigFiles [ $ name ] ; } } // add root templates $ rootTemplates = $ this -> findTemplates ( $ this -> containerUtil -> getProjectDir ( ) . '/templates/' ) ; if ( \ is_array ( $ rootTemplates ) ) { foreach ( $ rootTemplates as $ file ) { $ name = basename ( $ file ) ; $ legacyName = false !== strpos ( $ name , 'html.twig' ) ? basename ( $ file , '.html.twig' ) : $ name ; self :: $ twigFiles [ $ name ] = $ file ; if ( $ legacyName !== $ name ) { self :: $ twigFiles [ $ legacyName ] = self :: $ twigFiles [ $ name ] ; } } } return self :: $ twigFiles ; }
Get a list of all available templates.
Get a list of all available templates .