src/Template/TemplateUtil.php
public function getBundleTemplate(string $name, string $format = 'html.twig'): string
    {
        $templatePath = $name;

        $bundles = $this->kernel->getBundles();
        // if file from Controller::getTemplate() does not exist, search template in bundle views directory and return twig bundle path
        if (\is_array($bundles) && '.twig' === substr($format, -5)) {
            $pattern = $name.'.'.$format;

            foreach (array_reverse($bundles) as $key => $value) {
                $path = $this->kernel->locateResource("@$key");
                $finder = new Finder();
                $finder->in($path);
                $finder->files()->name($pattern);
                $twigKey = preg_replace('/Bundle$/', '', $key);

                foreach ($finder as $val) {
                    $explodurl = explode('Resources'.\DIRECTORY_SEPARATOR.'views'.\DIRECTORY_SEPARATOR, $val->getRelativePathname());
                    $string = end($explodurl);
                    $templatePath = "@$twigKey/$string";

                    break 2;
                }
            }
        }

        return $templatePath;
    }
public function getBundleTemplate(string $name, string $format = 'html.twig'): string
    {
        $templatePath = $name;

        $bundles = $this->kernel->getBundles();
        // if file from Controller::getTemplate() does not exist, search template in bundle views directory and return twig bundle path
        if (\is_array($bundles) && '.twig' === substr($format, -5)) {
            $pattern = $name.'.'.$format;

            foreach (array_reverse($bundles) as $key => $value) {
                $path = $this->kernel->locateResource("@$key");
                $finder = new Finder();
                $finder->in($path);
                $finder->files()->name($pattern);
                $twigKey = preg_replace('/Bundle$/', '', $key);

                foreach ($finder as $val) {
                    $explodurl = explode('Resources'.\DIRECTORY_SEPARATOR.'views'.\DIRECTORY_SEPARATOR, $val->getRelativePathname());
                    $string = end($explodurl);
                    $templatePath = "@$twigKey/$string";

                    break 2;
                }
            }
        }

        return $templatePath;
    }
public function getBundleTemplate ( string $ name , string $ format = 'html.twig' ) : string { $ templatePath = $ name ; $ bundles = $ this -> kernel -> getBundles ( ) ; // if file from Controller::getTemplate() does not exist, search template in bundle views directory and return twig bundle path if ( \ is_array ( $ bundles ) && '.twig' === substr ( $ format , - 5 ) ) { $ pattern = $ name . '.' . $ format ; foreach ( array_reverse ( $ bundles ) as $ key => $ value ) { $ path = $ this -> kernel -> locateResource ( "@$key" ) ; $ finder = new Finder ( ) ; $ finder -> in ( $ path ) ; $ finder -> files ( ) -> name ( $ pattern ) ; $ twigKey = preg_replace ( '/Bundle$/' , '' , $ key ) ; foreach ( $ finder as $ val ) { $ explodurl = explode ( 'Resources' . \ DIRECTORY_SEPARATOR . 'views' . \ DIRECTORY_SEPARATOR , $ val -> getRelativePathname ( ) ) ; $ string = end ( $ explodurl ) ; $ templatePath = "@$twigKey/$string" ; break 2 ; } } } return $ templatePath ; }
Find a particular template file within all bundles and return its path.

@param string $name   The name of the template
@param string $format The file extension

@throws \InvalidArgumentException If $strFormat is unknown
@throws \RuntimeException         If the template group folder is insecure

@return string The path to the template file
Find a particular template file within all bundles and return its path .