🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Content vs. Structure

posted in Rarely Spoken
Published May 24, 2005
Advertisement
I'd like to make my CMS as flexible as possible when it comes to the layout of the page but at the same time I have very specific types of content that must be included. Originally I had planned to have the XHTML written into the same page that breaks up the URL and retrieves the correct data but that would mean that casual users of the CMS might be scared away from changing the out-of-the-box layout because of all that PHP in there. So this is the solution I'm going to implement:

When the index breaks up the URL there are three different cases:

  • The URL is pointing to a real document

  • The URL is pointing to the index

  • The URL is pointing to a virtual document



The case of the real document is easy: I simply include that document.

The case of the index is a little bit more complicated: I have to output the template and fill it with the front page. The front page is dynamic content and is generated by whichever module is designated as the default module.

The final case is slightly more complicated still: I have to output the template and fill it with the dynamic content as parameterized by the rest of the URL.

The front page is generated by a module as if the module was asked to display content with no parameters so it seems like these two cases can be combined into one. Each module already has functions to generate content so it seems like all I'll have to do is call these in the correct place.

First let's look at the current code that handles these cases
// Does this file exist?if (file_exists($DOCUMENT_ROOT . $REQUEST_URI) and    ($SCRIPT_FILENAME != $DOCUMENT_ROOT . $REQUEST_URI) and    ($REQUEST_URI != '/')) {   // The file exists, simply include it   include($DOCUMENT_ROOT . $REQUEST_URI);} else {   // The file does not exist, the content might be dynamic   $url = strip_tags($REQUEST_URI);   $url_array = explode('/', $url);         // The first element of the array is empty since the first char is '/'   array_shift($url_array);   if (empty($url_array)) {      // The request was for the index      if (DisplayFrontPage() == false)         print "Error loading front page";   } else {      // The first entry is the module to run, and so we must attempt      // to execute that module. The rest of the URL array become the      // module's arguments      $module = $url_array[0];      array_shift($url_array);               ExecuteModule($module, $url_array, GetRequestVars());   }}


ExecuteModule() will execute the module's content-generating function and that function will output the content to the browser so the XHTML code will need to be embedded within this if. Ugly.

This is how I'm planning to reorganize it
---index.php---// A generic function that prints the content of the URLfunction PrintModuleContent() {   $url = strip_tags($REQUEST_URI);   $url_array = explode('/', $url);         // The first element of the array is empty since the first char is '/'   array_shift($url_array);   if (empty($url_array)) {      // The request was for the index      if (DisplayFrontPage() == false)         print "Error loading front page";   } else {      // The first entry is the module to run, and so we must attempt      // to execute that module. The rest of the URL array become the      // module's arguments      $module = $url_array[0];      array_shift($url_array);               if (ExecuteModule($module, $url_array, GetRequestVars()) == false)         print "Error loading page";   }}      // Does this file exist?if (file_exists($DOCUMENT_ROOT . $REQUEST_URI) and    ($SCRIPT_FILENAME != $DOCUMENT_ROOT . $REQUEST_URI) and    ($REQUEST_URI != '/')) {   // The file exists, simply include it   include($DOCUMENT_ROOT . $REQUEST_URI);} else {   // The file does not exist, the content might be dynamic   // Output the template   require_once('template.php');}---template.php---.......class="content">   PrintModuleContent();?>...


Now the user is free to make a template that is mostly free from PHP. The PHP parts will probably be labeled as 'Place this code where you want your content to show up'.

There we go! A basic template system.
Previous Entry OMFGWTFBBQ! An Update!
Next Entry Oh No!
0 likes 2 comments

Comments

Rob Loach
You know you can have something like this:

// test.php
if ((@include('file.php') == 'OK') {
   echo 'included';
} else {
   echo 'not included!';
}

// file.php
echo 'Sup guy!';
return 'OK';
May 25, 2005 10:19 AM
Colin Jeanne
Yes. Actually, for the modules, they are using that mechanism to return an array of the various content generating functions.

If your comment was meant specifically towards the template issue please explain! I'm interested in different methods as well.
May 25, 2005 12:17 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

4E6 PyGame

1404 views

4E5

1138 views

Happy Yesterday!

1093 views

Another Game

1305 views

Merry Christmas!

1073 views

Hello There

1072 views

Yay!

1088 views
Advertisement