doubu4826
2014-04-10 20:40
浏览 48
已采纳

使用Twig和Slim在父模板中重复数组

I've just started using Slim and Twig and getting to grips with it all.

I am building a small site and will have a Twitter feed on every page. So, I want to put this in my layout template (base.html.twig). The only way I can see to do it is to pass it in to every route and then use an include that can access the details.

Seems like there must be a way to set it in the layout template once without passing it in through every route?

Any help or a related link would be great.

图片转代码服务由CSDN问答提供 功能建议

我刚刚开始使用Slim和Twig并掌握所有这些内容。 \ n

我正在建立一个小网站,每个页面都有一个Twitter提要。 所以,我想把它放在我的布局模板(base.html.twig)中。 我能看到的唯一方法是将其传递到每个路由,然后使用可以访问详细信息的include。

似乎必须有一种方法在布局模板中设置一次而不通过每条路径传递它?

任何帮助或相关 链接会很棒。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douhui5953 2014-04-10 21:18
    最佳回答

    you can extend twig with user defined functions, just make a call inside template and you will not need for passing it every time http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题