Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取所有细枝模板的列表Symfony_Symfony_Templates_Twig_Symfony 2.8 - Fatal编程技术网

获取所有细枝模板的列表Symfony

获取所有细枝模板的列表Symfony,symfony,templates,twig,symfony-2.8,Symfony,Templates,Twig,Symfony 2.8,我搜索一种方法来获取Symfony2项目中所有细枝模板的列表。 我希望得到这样的结果: - AcmeBundle:Default:list.html.twig - OtherBundle:ParentFolder:new.html.twig 你知道吗 谢谢。您好,您可以尝试此代码,但需要进行调整 $kernel = $this->container->get('kernel'); $bundles = $kernel->getBundles(); $

我搜索一种方法来获取Symfony2项目中所有细枝模板的列表。 我希望得到这样的结果:

- AcmeBundle:Default:list.html.twig 
- OtherBundle:ParentFolder:new.html.twig
你知道吗


谢谢。

您好,您可以尝试此代码,但需要进行调整

    $kernel = $this->container->get('kernel');
    $bundles = $kernel->getBundles();
    $res = array();
    foreach ($bundles as $key => $value) {
        $path = $kernel->locateResource("@$key");
        $array = explode('\\', $path);
        if (in_array('vendor', $array))
            continue;
        $finder = new Finder();
        $finder->in($path);
        $finder->files()->name('*.twig');
        foreach ($finder as $val) {
            $explodurl = explode('Resources\views\\', $val->getPathname());
            $string = end($explodurl);
            $string = str_replace("\\", ':', $string);
            $res[] = "$key:$string";
        }
    }
     dump($res);
在unix(nginx)中使用它


您可以复制在中找到的GetLoaderPath

或者只是使用

$loader=$this->twig->getLoader()


由于加载程序将包含路径列表

您好,您可以使用Finder搜索包含细枝扩展的文件。我已经尝试过了,但它没有给出所需的结果。非常确定没有主列表。您可以查看var/cache/env//twig下的“编译”细枝文件。每个文件中的第一条注释如下:/*@WebProfiler/Collector/config.html.twig*/谢谢,功能很好
 $res = array();
    foreach ($this->getBundles() as $key => $value) {
        $keyAlias = $value->getName();
        $path = $kernel->locateResource("@$keyAlias");
        $array = explode('//', $path);
        if (in_array('vendor', $array))
            continue;
        $finder = new Finder();
        $finder->in($path);
        $finder->files()->name('*.twig');
        foreach ($finder as $val) {
            $explodurl = explode('//Resources/views/', $val->getPathname());
            $string = end($explodurl);
            $string = str_replace("/", ':', $string);
            $res[] = "$keyAlias:$string";
        }
    }
   dump($res);

private function getBundles() {
    $kernel = $this->getContainer()->get('kernel');
    $bundles = [];
    $allBundles = $kernel->getBundles();
    foreach ($allBundles as $bundle) {
        $reflection = new ReflectionClass($bundle);
        $bundleDirectory = dirname($reflection->getFileName());
        if (!preg_match("/vendor/i", $bundleDirectory, $matches)) {
            $bundles[] = $bundle;
        }
    }
    return $bundles;
}