Symfony EventSubscriber 更改树枝渲染路径
我会问您动态更改从控制器调用的 $twig->render 路径的正确方法。
我想创建自定义加载程序或事件订阅者,其工作原理如下: 当我设置参数/参数并从控制器
return $this->render('system/create.html.twig');
树枝调用时,将检查路径中的模板是否
system/custom/variable_name/create.html.twig
存在,加载它,如果不存在,加载正常路径
system/create.html.twig
我找不到正确的方法来实现它,不知道我应该使用什么,EventSubscriber (以及如何订阅渲染方法),或者只是使用一些自定义 Twig 加载器来实现它?
@编辑 问题解决了!无法“即时”执行此操作,因此我在自定义类中扩展 AbstractController,覆盖渲染方法并检查此方法中的所有条件。
i would ask You about proper way to change dynamicly the $twig->render path called from controller.
I want to create custom loader or event subscriber, which works like:
when i set parameter/param and call from controller
return $this->render('system/create.html.twig');
twig will check, if template in path
system/custom/variable_name/create.html.twig
exists, load it, if not, load normal path
system/create.html.twig
I can't find proper way to realize it, have not idea, what i should use, EventSubscriber(and how to Subscribe on render method), or just realize it with some custom Twig loader?
@EDIT
Problem solved! There is no way to do it "on the fly", so i extend AbstractController in custom Class, override render method and check in this method all conditions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论