Dynamic menu with symfony in template

人走茶凉 提交于 2019-12-07 13:08:07

问题


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?


回答1:


Put your menu-creating logic in a new controller, and use twig's {% render %} to include it in your page. See embedding controllers.



来源:https://stackoverflow.com/questions/9234530/dynamic-menu-with-symfony-in-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!