繁体   English   中英

Symfony-从javascript(前端)和控制器(后端)访问树枝模板

[英]Symfony - accessing twig templates both from javascript (frontend) and controllers (backend)

我使用模板的第一种方法是标准的symfony方法-从控制器调用:

return $this->render('MyBundle:MyController:MyTemplate.html.twig');

模板存储在Resources/views/MyController/MyTemplate.html.twig

我使用模板的第二种方法是前端。 我正在使用twig.js ,模板存储在Resources/public/twig /bundles/mybundle/twig文件夹中(可从js的/bundles/mybundle/twig访问它们)

问题。 例如,我想在正面和背面使用相同的macro 我无法从public模板访问views ,也无法从存储在views中的模板访问public views

当前使用Ctrl + C / Ctrl + V:/

我为我找到了一个非常简单的解决方案:

config.yml

twig:
    paths:
        "%kernel.root_dir%/../src/Ida/BabolaBundle/Resources/public/twig": public

现在,我可以在任何views模板中使用@public/myTemplate.html.twigviews访问public

这也是此功能的PHPStorm提示:

Settings -> Other Setting -> Symfony2 Plugin -> Twig / Template添加新行

public src/YourVendor/YourBundle/Resources/public/twig ADD_PATH Custom true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM