Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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
Php 小枝中束的相对路径_Php_Symfony_Twig - Fatal编程技术网

Php 小枝中束的相对路径

Php 小枝中束的相对路径,php,symfony,twig,Php,Symfony,Twig,我在Twig文件中获得了标准扩展名: {% extends 'AcmeMyBundle:Layout:defaultLayout.html.twig' %} 我可以用包的相对名称来调用这个模板文件吗? 例如 与dir路径类似:“./relative/path/to/file.ext”只需编辑Config.yml文件: # app/config/config.yml twig: # ... paths: "%kernel.root_dir%/../src/acme

我在Twig文件中获得了标准扩展名:

{% extends 'AcmeMyBundle:Layout:defaultLayout.html.twig' %}
我可以用包的相对名称来调用这个模板文件吗? 例如


与dir路径类似:“./relative/path/to/file.ext”

只需编辑Config.yml文件:

# app/config/config.yml
twig:
    # ...
    paths:
        "%kernel.root_dir%/../src/acme/myBundle/Resources/views": foo_bar
然后您就可以访问相对路径——您只需在config.yml中更改路径,而不是在每个include行中更改路径

# view.html.twig
{% include '@foo_bar/Layout/defaultLayout.twig' %}

你可以试试,你就会知道你是否可以调用它。不可以,但是看看细枝名称空间:没有自定义代码,尝试它肯定会比写这个问题花费更少的时间。所以,在app/config/config.yml中,我可以添加自定义路径。我很好奇这是一个什么样的实际用例?
# view.html.twig
{% include '@foo_bar/Layout/defaultLayout.twig' %}