MVC: Repeating content

How do you guys handle includes for html that gets repeated through many pages while keeping MVC in mind?

IE. Footers, side navigation, etc etc.

Do you just do a include? Or assign a variable to hold the include and echo it out in the html side?

I separate out things like that into their own controller making it possible to reuse them anywhere.

Actually I was just thinking about it, and my logic was off a bit. I was separating pages into individual ones even though I could have just done something like: domain.com/page/view/other/params

PS. Didn’t mean to hijack the thread :slight_smile:

Footers, side navigation etc. may contain dynamic parts, dependent on main content … so separate controller bound to some Context dispatcher is a way to go.

Try to never have any duplicated code in your site.
If you have a header on 2 pages, then make it an include.
If your selected page needs to be highlighted, then add that code in the included header.

Do this until you learn more PHP and get some experience with websites.

After you make a few sites, you will notice the need for front controllers (chances are so far your using page controllers).

I have nested view objects:

1: make a master view for whole app - kick off output buffering on app startup
2: nominate a master layout template
3: inject view helper into each controller class - start new output buffer
4: render controller output into the view for that controller
5: flush controller view output into a variable
6: render that variable into the master template