PHP Classes

File: example1.php

Recommend this page to a friend!
  Classes of Jeff Williams   Easy Template   example1.php   Download  
File: example1.php
Role: Example script
Content type: text/plain
Description: Example 1 - Old style comment tags
Class: Easy Template
Template engine based on real HTML tag replacement
Author: By
Last change: Initial Release
Date: 17 years ago
Size: 1,458 bytes
 

Contents

Class file image Download
<?php
include("template.class.php");

// Create the template object
$template = new Template("example1.html");

// Replace the tags with real data
$template->replaceTag("NameTag", "John Doe");
$template->replaceTag("TextFieldTag", "This is a textbox value");

// Template::getHTMLChecked returns selected="selected" if the value passed
// in is true, "on", "selected", "checked", "yes", "y", "true", or "t"
$template->replaceTag("CheckedTag", Template::getHTMLChecked(true));

/*
NOTE: you cannot execute any PHP code in a template file by default.
That means that server side includes are not possible in templates as is.

One way we could show more than one page if we needed to and
emulate a server side include would be to use the following:

  $templateHeader->showPage();
  $templateMain->showPage();
  $templateFooter->showPage();

Or you could replace a tag with the code from another template:

  $templateMain->replaceTag("HeaderTag", $templateHeader->getPage());
  $templateMain->replaceTag("FooterTag", $templateFooter->getPage());

Or we could grab executed PHP code from a web page! Executed code
can then be used to replace a tag in a template file:

  $template->replaceTagFromWeb("TagName", "http://google.finderg.com");

Or we can load data directly from any file to replace a tag instead!
*/
$template->replaceTagFromFile("JavaScriptTag", "example1.js");

// Show the page
$template->showPage();
?>