Symfony2 - 在每次页面请求时在 layout.html.twig 中填充导航栏 [英] Symfony2 - populate navigation bar in layout.html.twig on every page request

查看:29
本文介绍了Symfony2 - 在每次页面请求时在 layout.html.twig 中填充导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 layout.html.twig 中,我有一个带有一些链接的导航栏.我希望从数据库中填充链接.

In my layout.html.twig I have a navigation bar with some links. I want the links to be populated from a database.

例如,在导航栏中,我有一个最近的产品"下拉菜单.如何从数据库填充主 layout.html.twig 中的下拉列表?(当然以后会缓存)

For example, in the navigation bar I have a drop down of 'Recent Products'. How can I populate the dropdown in the main layout.html.twig from a database? (of course it'll be cached in the future)

我需要创建过滤器吗?

任何帮助都会很棒.谢谢

Any help would be great. Thanks

注意:在 Symfony 1.4 中,我会使用一个组件.这在 Symfony 2 中存在吗?

Note: In Symfony 1.4 I would have used a component. Does this exist in Symfony 2?

推荐答案

答案在这里:http://symfony.com/doc/2.0/book/templating.html#embedding-controllers

我需要创建一个子控制器,然后将子控制器视图嵌入到主树枝布局中.

I needed to create a sub-controller and then embed the sub-controller view into the main twig layout.

这篇关于Symfony2 - 在每次页面请求时在 layout.html.twig 中填充导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆