• Advertisement
Sign in to follow this  

[web] Asp.net-like master pages in php

This topic is 2877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As it turns out, I have a small project coming up where I have to build a simple framework for a personal portfolio. The technology in use is PHP and up to this point I was planning on taking my usual template route. However, with a profane amount of time to let my mind wonder at work yesterday I started thinking back on my few experiences with ASP.net. Without a doubt, for me, one of the coolest features that was immediately accessible was the use of master pages and content pages. I've been pondering how I might be able to emulate such a feature since then. My initial thought was that I'd probably have to write some kind of CGI script to intercept the file request and process it there but since I don't know squat about how to do that I figured I should try to solve my problem with Php first. Currently, the only idea I can come up with is to build a master page as you would in Asp.NET by using <contentplaceholder id> tags everywhere that you would expect things to be inserted. At the top of every content page it would then be a simple matter of calling a utility interface, maybe like so:
include "masterpageutil.php"
The ugly side of this however is in how it would be handled. Currently, my meager knowledge of Php has lead me to this point: Upon calling the above display function, I would open up the current page as a file, parse through it's contents and collect everything contained within <content id> tags in an associative array based on their id. Then I would open the given master page file, parse its contents and look for <contentplacholder id> tags. Everywhere I find a placeholder that has an id matching a previously stored content section, i would just insert the text. All of this might be stuffed into a rather giant string and finally echoed out to the browser. Obviously, this has a lot of pitfalls, not the least of which is that I lose all ability to process actual php scripts in the page. Luckily, the person I'm building this for isn't really keen on anything beyond HTML and CSS and so, won't have much use for php (otherwise I would have just gone with the template scheme in the first place). Also, I imagine this would probably not scale well in bigger site. However, since this is for a personal website with a bit of portfolio information I doubt that will be much of an issue. Are there any suggestions on how I might better handle this? Any other serious issues that can be foreseen both in terms of security and functionality?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement