Thread: Template System - Variation

View Single Post

  #1 (permalink)  

Old 02-14-2005, 06:46 PM

Template System - Variation

My own kind of "template" system using variables passed through the URI (index.php?act=XX). Instead of having to define each of the variables, like so:
PHP Code:
if($_GET['act'] == "xx") {
    include(
"./files/xx.php");
                                }
if(
$_GET['act'] == "yy"){
    include(
"./files/yy.php");
                               } 
and so on, try this:

PHP Code:
if( (empty($_GET['act'])) || ($_GET['act'] == "home") ) {
    include(
"./files/home.php");
                                } else {
                                   include(
"./files/" $_GET['act'] . ".php");
                                          } 
Were we say, (first line) if the variable (?act == "") or (?act == home), include the home page.
BUT, if it does not (line 3), include the file ./files/x.php.
So for example, if the following page is requested: index.php?act=y, the script first checks to see if the ?act is empty or if it equals home. If it does, then include the home.php. If it is NOT empty, and does NOT equal home, include y.php.

Of course, this doesn't allow for much innovation, as you are pretty much secluded to doing ?act=filename, were as the other system you can do ?act=requestname and still include a totally different file.

But with this, you don't have to keep adding if clauses and all that jazz, because its "automatic"
[ reply ]
borednerd

borednerd is offline registered.

borednerd's Avatar

Join Date: Feb 2005

Posts: 31