Reputation: 10040
suppose I have a header area with some navigation links that I want to be visible by many pages in my application.
I understand I could add the header as a block, and override this block in all of the child pages. But this would mean my logic to display the dynamic content would have to be replicated in every controller for every page I have (I think)?
Is there a way I can just have one controller, or at least have one area of the PHP code that is called just once, to populate the navigation links in the header that will be shared by many files?
Thank you
Upvotes: 0
Views: 182
Reputation: 10910
How about creating block for header in parent template and creating single controller which will be responsible for generating content for this block. Then in your every child template you call this single controller by code like this:
{{ render(controller('AcmeArticleBundle:Article:recentArticles', {
'max': 3
})) }}
As you can see you can pass arguments, which may be handy in your case. Check doc for more info
Upvotes: 2