0

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for your answer. I was eventually able to achieve the outcome I wanted using Twig Extensions!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.