Php 小枝中束的相对路径
我在Twig文件中获得了标准扩展名: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
{% 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' %}