tags:

views:

254

answers:

5

Is there any way to achieve the master page concept of ASP.NET in PHP?

+3  A: 

You could use a template engine like Smarty:

Although Smarty is known as a "Template Engine", it would be more accurately described as a "Template/Presentation Framework." That is, it provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application.

Andrew Hare
+2  A: 

Of course it's possible. Have a look here. It shows a basic way of doing it, which of course, you can extend. Good luck!

aredkid
This looks simple! Good one for naive users :)
Vijay
+2  A: 

As other said, the way to go is to use a template engine. My preference goes to the Zend Framework, which is a bit more than just templates ;), but has a nice implementation of a layout with Zend_Layout that is very close to Master Pages in ASP.Net.

Check the quickstart guide to have an idea of how this works, and have a look at the full doc to see the possibilities offered by the framework. Plus, using the framework gives you a nice MVC architecture and SEO-friends rewritten URLs...

Wookai
+1 for not suggesting Smarty.
Gordon
A: 

You can use auto_prepend_file and auto_append_file together with output buffering.

troelskn
A: 

I made a simple proof-of-concept for a asp-like master pages in PHP. You can get it here: http://code.google.com/p/phpmasterpages/

Nicolas Rodriguez