在模板中使用symfony的动态菜单 [英] Dynamic menu with symfony in template
问题描述
p>将菜单创建逻辑放在新的控制器中,并使用twig的 {%render%}
将其包含在您的页面中。请参阅嵌入控制器。
I'm building a symfony website and I've my own code to build dynamically a menu with subitems. Right now I print it with a bit of twig code inside the base.html.twig file (master layout). The problem is when I need to pass the array with the items of the menu. I'm actually passing it to the render method of a single controller but obvsiously when I switch page I get a non-existent variable. How can I have a single location to put my php code to build the menu array and execute it every time a page is rendered?
Put your menu-creating logic in a new controller, and use twig's {% render %}
to include it in your page. See embedding controllers.
这篇关于在模板中使用symfony的动态菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!