Location: PHPKode > scripts > Easy Template > example3.php
Easy Template Example
This example uses actual form controls as replace tags

// Let's include the class file and create a new template object
$t = new TemplateHTML("example3.html");

// Easy Template can create dropdowns, lists, and tables from arrays
$array = array(
    array("EmployeeID" => "1", "FirstName" => "Bob",   "LastName" => "Smith", "Region" => "West"),
    array("EmployeeID" => "2", "FirstName" => "John",  "LastName" => "Jones", "Region" => "North"),
    array("EmployeeID" => "3", "FirstName" => "Susan", "LastName" => "King",  "Region" => null),
    array("EmployeeID" => "4", "FirstName" => "Jane",  "LastName" => "Duncan","Region" => "East"),
    array("EmployeeID" => "5", "FirstName" => "Steven","LastName" => "Miller","Region" => null)

// We could instead grab an array from the Ultimate MySQL database class
// http://www.phpclasses.org/browse/package/3698.html
$db = new UltimateMySQL();
$db->Query("SELECT EmployeeID, FirstName, LastName, Region FROM employees");
$array = $db->RecordsArray(MYSQL_ASSOC);

// Let's set up some example style information for a table
// NOTE: the style information in the opening TABLE and SELECT tags
// will not be changed so you can set style information in the template
$trHeader = 'style="color: rgb(204, 0, 0);"';
$tdHeader = 'style="font-weight: bold;"';
$tr = 'style="background-color: rgb(204, 255, 255);"';
$td = 'style="font-family: Helvetica,Arial,sans-serif;"';
$tr2 = 'style="background-color: rgb(255, 255, 204);"';
$td2 = 'style="font-style: italic;"';

// Replace actual elements and data in the HTML of the template
// NOTE: You could also inject data from another file, a string,
// another template, or even another live web page!

// Replace the actual table data in the page!
$t->replaceHtmlTableData("table3", $array, true, 1, $trHeader, $tdHeader, $tr, $td, $tr2, $td2);

// Let's replace the SELECT dropdown data with our array yet
// leave the SELECT intact with all style/attribute information!
// That means you can make your templates in ANY HTML editor
$t->replaceHtmlSelectData("MyList", $array, "FirstName", "EmployeeID", "5", false, 1);

// Replace ANY tag's data
$t->replaceHtmlElementData("caption", "MyCaption", "This caption has been replaced");

// Use div's as a template tag
$t->replaceHtmlElement("div", "MyDiv", "<h2>Test Template</h2>");

// We'll even replace this textbox with a checkbox
$t->replaceHtmlElementTag("input", "MyTextbox", '<input type="checkbox" />Now it\'s a checkbox');

// Show our new page
Return current item: Easy Template