MaiaTech Web Hosting and Online Application Development

Home

Web Hosting and Domain Registration
Domain
Registration

Domain Registration
Web Hosting
Web Hosting
Help
Help Web Hosting and Domain Registration Clients
Contact Us
Contact Us for Web Hosting and Domain Registration

Sign Up
Online


Client
Web Sites


Pay Bills
Online


Latest News






Powered by
The Penguin

Get Firefox!

Get Free Online
Disk Space!

VarPage Class

VarPage is a replacement for ShellPage, a VERY simple PHP class for building websites based on Template files.

All you have to do is design a template HTML file with a few comment tags in it, as the master design for your site. Then create each of your web site's pages as a PHP page that calls VarPage and embeds your content into the template.

VarPage makes the improvement over ShellPage that you can replace any number of areas of your page with different content.

Below is the class code itself. You can select and copy it to your own text editor. Save it as VarPage.class.php and upload it somewhere on your PHP default include path.

VarPage.class.php

<?php
class VarPage {

   var $templatefile = "./template.html";
   var $varnamelist = "title,content";
   var $title = "Page Title Here";
   var $content = "<p>Page Content Here</p>";

   function VarPage(){
   }

   function display_page() {
      $vararray = explode(",",trim($this->varnamelist));
      $templatearray = file($this->templatefile);
      $template = join("",$templatearray);
      foreach ($vararray as $varname) {
         $template = str_replace("<!--$varname-->",$this->$varname,$template);
      }
      print $template;
   }
}
?>

Usage Example

To use VarPage, simply create a web page, with banner, menu, etc., as you want it to appear on every page. Then place HTML comments on your page for each area where you want content to be different on each page. For example put "<!--title-->" where you want the page title to appear, "<!--headline-->" where you want the headline, and put the "<!--content-->" where you want the page content to be inserted.

Then you are ready to make as many pages as you want. In each page you must include the VarPage class, declare a new VarPage, set the template file and the list of variables, then assign values to each variable. Below is an example:

<?php
include("./VarPage.class.php");

$page = new VarPage;
$page->templatefile = "./template.html";
$page->varnamelist = "title,headline,content";

$page->title = "Welcome To My Page";

$page->headline = "What My Page Is About";

$page->content .= <<<EOD
<p>Some regular text on my page. <b>Bold Blah blah blah blah.</b>
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah. 
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah. 
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah. 
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah. 
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah. 
Blah blah blah blah. Blah blah blah blah. Blah blah blah blah.</p>
<p><a href="/">Back To Home Page</a></p>
EOD;

$page->display_page();
?>

 

 
Online I Ching for Mobile Browsers


   • 410-788-1148 • © MaiaTech 2004