在另一个树枝变量中执行一个树枝变量 [英] Execute a twig variable inside another twig variable
问题描述
我正在做一个 symfony2 项目.在文件 html.twig
中,我有以下代码:{{ app.session.get('menu') |raw }}
指的是会话中包含的数据库表中的字段.该字段的值为:
此时菜单已完美显示,但是当我单击Graphe"时,出现错误 No route found for GET/{{ path('graphe') |raw}}
这意味着代码不会被执行,而是被当作一个字符串.有没有其他方法可以执行.提前致谢.
在你的 twig 模板中嵌入一个控制器来呈现你的用户菜单.有关更多信息,请参阅:
http://symfony.com/doc/current/book/templating.html#embedding-controllers
I'm working on a symfony2 project. In a file html.twig
i have the following code: {{ app.session.get('menu') | raw }}
that refers to a field in a database table contained in a session. The value of this field is :
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Menu1</a>
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="{{ path('graphe') | raw}}">Graphe</a></li>
</ul>
</div>
</div>
Now at this point the menu is displayed perfectly, but when i click on "Graphe", i get the error No route found for GET /{{ path('graphe') | raw}}
which means that the code is not executed but taken as a string instead.
Is there any other way it can be executed. Thank you in advance.
In your twig template embed a controller which renders your user menu. For more info see:
http://symfony.com/doc/current/book/templating.html#embedding-controllers
这篇关于在另一个树枝变量中执行一个树枝变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!