PHP Equivalent of Master page in ASP.NET
Asked Answered
K

7

27

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

Kiaochow answered 19/12, 2009 at 15:20 Comment(0)
N
5

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.

Nagana answered 19/12, 2009 at 15:22 Comment(0)
E
20

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!

Elison answered 19/12, 2009 at 15:24 Comment(1)
This looks simple! Good one for naive users :)Kiaochow
N
5

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.

Nagana answered 19/12, 2009 at 15:22 Comment(0)
T
5

You can use auto_prepend_file and auto_append_file together with output buffering.

Touchy answered 19/12, 2009 at 16:49 Comment(2)
I like output buffering as an easy, effective solution. Here's a guide that shows how to approximate master pages using output buffering - spinningtheweb.blogspot.com/2006/07/…Peyter
Definitely the best answer (with addition from @Peyter :) )Corroboree
P
5

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/

Plumbo answered 25/5, 2010 at 18:3 Comment(0)
W
4

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...

Wiltonwiltsey answered 19/12, 2009 at 15:28 Comment(0)
M
0

Maybe just use include() since the variables in both file are in the same scope. Also ob_start() can record the output to the buffer so that the html codes can output later.

Mediacy answered 15/6, 2011 at 9:7 Comment(0)
B
0

The best and easy way to do is using include as other said. Create a header.php and footer.php and include them in every page you want to use. The approach is bit different compare to asp.net master pages but is as powerful as master pages

Buddybuderus answered 18/2, 2018 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.