PHP Classes

plato: Template parsing engine

Recommend this page to a friend!
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 897 All time: 3,920 This week: 186Up
Version License Categories
plato 1.0FreewareTemplates
Description Author

Plato is a based template parsing engine which uses both regular expressions and string replacement functions.

It is very extensible and allows users to create their own plugins.

It has the ability to insert variables, include files, make function calls to plugins, and perform loops.

Read the readme.txt file to learn more details.

Picture of Rick Hopkins
Name: Rick Hopkins <contact>
Classes: 4 packages by
Country: United States United States
Age: 43
All time rank: 56670 in United States United States
Week rank: 352 Up33 in United States United States Up

Plato PHP Template Parsing Engine
Rick Hopkins
v. 0.0.5

v. 0.0.7

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 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
	// 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
	// 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

index.php = 
	$pl = new plato();
	$pl->assign("title", "Test Page");

index.tpl = 
index.tpl after parsing =
	<title>Test Page</title>

Example Plato Markup
Simple variable replacement
variableName is replaced with the assigned value

Include File Call
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=_date&var[format]=F d, Y&var[date]=2004-03-27&var[message]=: My Birthday}
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 - 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
Created the ability to assign filenames to variables through assign method
and pass them into the plato_include method.
$pl->assign("header", "header.tpl");


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.

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. 
  Files folder image Files  
File Role Description
Accessible without login Plain text file footer.tpl Example footer template file
Accessible without login Plain text file header.tpl Example header template file
Accessible without login Plain text file index.php Example example php index file
Accessible without login Plain text file index.tpl Example index template file
Accessible without login Plain text file Aux. date plugin
Plain text file Class template engine
Accessible without login Plain text file plato.stateSel.php Aux. state select box plugin
Accessible without login Plain text file plato.test.php Aux. test function plugin
Accessible without login Plain text file readme.txt Doc. Documentation & Instruction

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:3,920
This week:186Up
For more information send a message to info at phpclasses dot org.