PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of Rick Hopkins   plato   readme.txt   Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: Documentation & Instruction
Class: plato
Template parsing engine
Author: By
Last change: Added to change log.
Date: 20 years ago
Size: 5,693 bytes
 

Contents

Class file image Download
Plato PHP Template Parsing Engine ------------------------------------- Rick Hopkins 01.30.2004 v. 0.0.5 UPDATED ------------------------------------- 02.19.2004 v. 0.0.7 See CHANGE LOG Instructions: -------------- Plato is a fairly simple class to understand and use. The way I sat up Plato was as follows: 1) Create a directory called 'lib' at the webserver root which is where the plato.inc file will reside. 2) Inside the 'lib' directory create another directory called 'plugins'. The 'plugins' directory is where you will place any and all plugins created for use with Plato. The naming convention that Plato needs to have for the functions is as follows: - plato.functionname.php This format is used within the Plato engine to create a list of usable plugins. 3) Create a directory called 'tpl' at the webserver root which is where all your template files will be stored. Template files, at least the way I did it, were stored with an extension of .tpl. This isn't necessary, but I found it easier later on when we get to includes. 4) My index.php file is at the webserver root with all the php and class generation code within it. Explanation Of Code ----------------------- <?php require("lib/plato.inc"); // start up plato class $pl = new plato(); // assign all variables $pl->assign("argVal", "Rick Hopkins<br>Web Developer<br>Morrison Industrial Equipment<br>Grand Rapids, Michigan"); $pl->assign("name", array("John Smith", "Mary Smith", "John Smith Jr.")); $pl->assign("age", array("25", "23", "3")); $pl->assign("position", array("Dad", "Mom", "Son")); $pl->assign("title", "Plato Template System Test Run"); $pl->assign("test1", "This is a test of the Plato Template System."); $pl->assign("test2", "This template system can load files as includes, set variables, and perform functions.<br>The code is easily extendable and users can write their own functions to work as Plato plugins."); $pl->assign("footerTest", "This is the footer section of the page.<br>It was pulled into the page by a plato include command."); // create the page $pl->display("index.tpl"); // do a speed check print("<br><h1><b>File Parse Time:</b><hr>".$pl->getParseTime()."</h1>"); ?> - First we create a new class - Next we assign all variables - Finally we parse the given tpl file - the speed check was thrown into the file just to see how fast it is example: index.php = $pl = new plato(); $pl->assign("title", "Test Page"); $pl->display("index.tpl"); index.tpl = <html> <title>{title}</title> </html> index.tpl after parsing = <html> <title>Test Page</title> </html> Example Plato Markup ------------------------ Simple variable replacement {variableName} variableName is replaced with the assigned value Include File Call {plato_include=footer.tpl&type=tpl} The contents of footer.tpl are inserted wherever this tag is at in the code. The type variable can be tpl, css, or js. tpl = any file containing containing html which needs to be appended to parsed file css = will create a css link tag to the css file given js = will create a javascript script tag with href link to the js file given Function call to a plugin {plato_func=_test&var=argVal&ref=1} {plato_func=_date&var[format]=F d, Y&var[date]=2004-03-27&var[message]=: My Birthday} {plato_func=_stateSel&var[selected]=MI&var[class]=input} In each function call there are three essential parts - plato_func : the name of the function plugin called - var : can be a single phrase or an array; var=argVal or var[]=1&var[]=2 or var[time]=10:00pm&var[date]=01.30.2004 - ref : default is 0, if set to one var refers to assigned variable All parts are separated by an '&' sign and enclosed in brackets {} Plato Loop Functionality {plato_loop=name&id=outer} <tr> <td><h1>{name}</h1></td> <td><h1>{age}</h1></td> <td><h1>{position}</h1></td> </tr> {/outer} plato_loop=name - name is the variable which the loop is based upon whatever the count of the name array is, is how many times it will loop id=outer - every loop needs an identifier {/outer} closes out the loop It will loop the text that is between the two tags, replacing whatever variables are inbetween with the correct index from the array iteration. CHANGE LOG: last updated 02.19.2004 ------------------------------------ 02.19.2004 ------------------ Created the ability to assign filenames to variables through assign method and pass them into the plato_include method. index.php ---------- $pl->assign("header", "header.tpl"); index.tpl ---------- {plato_include=header&type=tpl&ref=1} ref=1 relates the plato_include=header to the header variable you assigned in index.php Future Improvements To Plato ------------------------------------ 1) An error handling system 2) More efficient and indepth loop functionality 3) Ability to create conditions ex: if then statements 4) Use of cache to speed up template parsing 5) Add your improvement here... There are no doubt many improvements that can be made, but I think this is a good start. Let me know if you have any improvements you would like to see. rhopkins_webdev@hotmail.com. Contact The Author ------------------------------ Let me know if you find this a useful tool or not. Possible improvements you come up with, cool plugins and extensions, suggestions for the future. Let me know if you have any applications use decide to use Plato in. I just really enjoy getting feedback for my work, good or bad, I don't care. I will try to respond to any questions best I can. Thanks. rhopkins_webdev@hotmail.com