Symfony2 - 在渲染模板之前注入代码

时间:2013-01-31 19:42:49

标签: php symfony smarty

我在我的Symfony2应用程序中添加了SmartyBundle。它运行良好,但我想将左(默认:{)和右(默认:})分隔符更改为[]。为此,我需要执行以下代码:

$smarty = $container->get('templating.engine.smarty')->getSmarty();
$smarty->left_delimiter = '[';
$smarty->right_delimiter = ']';

如何在控制器中渲染模板之前执行此操作?我想我需要使用EventListener,但我不确定如何。

1 个答案:

答案 0 :(得分:0)

您在内核中的使用请求侦听器。

如果smarty引擎有方法setLeftDelimiter和setRightDelimiter,你可以为你的bundle创建一个CompilerPass,获取定义并添加调用方法。

相关问题