 |
Title: Template System Marked Cool (Review this resource) Author: CWIZO Posted On: 2005-02-07 Category: Home > PHP Classes
Popularity:
Description: A class for managing template parsing and caching. Small but powerfull.
Total Hits: 999 Total Votes: 0
Total Points: 0 (0 reviews) [ Download ]
Page Navigation: [1]
Template system
This is a small class for template system. It contains 108 lines of code. It maybe small but it is veary powerfull.
Features:
- Caching support
- Use one template to store different data (use of IDs)
- PHP code can be inserted into the template and be executed
- Easy to use
- Easy to read source code
A template is a regular HTML file that must have a .tpl postfix insted of .html. It contains anchors which are then repalced with content by the template system.
A anchor is formated like this: {!AnchorName!}. First '{!' then the name of the anchor and finnaly '!}'.
You can use the same anchor name in different places across your template file.
To use this class, you must first create two folders one for templates (all your templates will be stored here) and one for cached templates. You pass the paths to this folders to the constructor of the template system.
You must include the Template.class.inc file to use the Template class.
Examples showing how to use this template system are in the index.php file located inside the download.zip file.
This are the methods that you can use:
- Template ( $TemplateFolder, $CacheFolder ) : constructor. $TemplateFolder (path to templates folder), $CacheFolder (path to cache folder)
- Replace ( $TemplateName, $ReplaceStrings ) : function for parsing the template. $TemplateName (name of the template to parse (without .tpl), $ReplaceStrings (array of data to be inserted into the template)
- Output ( $Content ) : function that outputs the parsed template (see example). $Content (contents of the Replace() output)
- CacheContent ( $TemplateName, $Id, $Content ) : function for storing template in a cache. $TemplateName (name of the template without .tpl), $Id (ID of the template, see example), $Content (contents of the Replace() output)
- IsCached ( $TemplateName, $Id ) : function for determening if the template is cached or not. $TemplateName (name of the template, without .tpl), $Id (ID of the template, see example)
- GetCachedContent ( $TemplateName, $Id ) : function that returnes the cached template. $TemplateName (name of the template, without .tpl), $Id (ID of the template, see example)
- ClearCache ( $TemplateName, $Id ) : function that clears a template from the cache. This function is not used in the examples becouse it's use is obvious. But to give an example where you would use this: You cache the user comments page, and when a user adds a new comment you clear the cache of that page so the page is generated again. $TemplateName (name of the template, without .tpl), $Id (ID of the template, see example)
Page Navigation: [1]
|
|
 |