Sample sites: this site (and all of Worx International Inc.) and our new video search engine
January 01, 2009 – NEW! Two new versions released! QuickSkin version 2.3 for PHP4, and QuickSkin version 5.0 for PHP5. New features include: new sample template, new code extensions, dp.SyntaxHighlighter included.
QuickSkin is a Template Engine that was designed to support web based applications of any size. It is particularly suited to large scale applications like Content Management Systems. The project was originally started by Philipp v. Criegern and named "SmartTemplate". The project was then taken over by Manuel 'EndelWar' Dalla Lana and HonestQiao. The name of the project back then led to confusion with Smarty Templating. Despite its advantages over other templating systems (speed, small footprint, ease of use, power), SmartTemplate has not been updated and had many outstanding bugs. Worx International Inc. has been using SmartTemplate on a variety of projects for several years. Over that time we have become very familiar with the code. We have now taken over the project. Our first task was to rename the project to make it less confusing, fix the bugs, and extend its capabilities -- while maintaining its core simplicity and ease of use.
What's so special about it?
Common template engines work like the following: Your PHP script specifies an HTML template and assigns some dynamic content to display. The template parser replaces all placeholders within the template with the assigned content and displays it to the user. This means a lot of string processing and regular expression work each time you want to display some content.
QuickSkin works like a 'template compiler' that converts templates into executable PHP code and stores it for later reuse. The first time a new template is processed, all placeholders in the template are replaced by small PHP code elements that print the assigned content. The HTML template fragment <H3></H3>, for example, is converted into something like <H3><?php echo $TITLE; ?></H3>. If you have assigned your content to the right variables, there is no need for any template parsing anymore. The only thing that has to be done is to include and execute the compiled template. This usually increases the execution time of the template engine dramatically.
• Simple Scalar Substitution (Strings, etc.)
• Block Iterations (nested Arrays / BEGIN..END)
• Basic Control Structures (IF..ELSEIF..ELSE)
• Custom Extension (Output filters, uppercase, sprintf, etc.)
• Template Compilation (HTML templates are converted to executable PHP Code)
• Output Caching (Accelerates your applications by reusing page output)
• November 2007: QuickSkin is now PHP5 compliant and tested up to and including PHP 5.2.4. It is not tested with E_STRICT. One package to support both PHP4 and PHP5.
Let's start with an easy example to show how to use QuickSkin:
Usually the process of creating a webpage begins with a preview of the future result. Creating simple layouts this can be done using a webeditor like Dreamweaver or Homesite. For more complex page layouts one should always consider using a professional design tool like Photoshop, Paintshop Pro, Gimp etc.
Now we create the HTML source that generates a web page of our desired design:
Now the exciting step: The separation of content and design. We replace all dynamic content elements in the HTML-scource by placeholders. They get a unique name and an own tag around them so we can identify them later. The title Hello World! is replaced by a placeholder named TITLE. We mark this placeholder by embedding it in curly brackets, so the template parser can find it: . The HTML Template now looks like the following:
To populate this template with content we have to:
- Load the QuickSkin Class
- Instantiate a QuickSkin Parser Object
- Tell QuickSkin which HTML-Template to use
- Assign the content to its associated placeholders
- Process Template
- Print result
The following PHP Script will do the required steps:
$page = new QuickSkin("hello_world.tpl.html"
$page->assign('TITLE', 'Hello World!');
That's all - our Hello World example is ready to run.
QuickSkin is compatible with all scripts previous written for SmartTemplate and only requires a change in the code calling the class. There are quite a number of new features you may wish to explore.