TACS – free PHP template and caching script
written by Craig, 21 June 2007
There are many good PHP templating systems available. However, some are very complex or require learning API commands rather than using your own PHP libraries.
This was the inspiration for TACS (Templating and Caching System). I wanted a simple system that allowed us to:
- easily include other files, such as headers, footers, etc.
- easily create and use variables
- cache and compress the HTML
- use my own PHP code for functionality
- specify PHP code blocks that output static HTML when the page is cached, e.g. processing arrays to create HTML menus
- specify normal PHP that runs every time the page is loaded, e.g. form processing, database connectivity, etc.
TACS provides these facilities and should work on any OS and web server that supports PHP4 or above.
To use TACS, include it at the top of your PHP page:
<?php require_once('relative_path_to_tacs/tacs.php'); ?>
All TACS instructions are enclosed in double square brackets; [[command]]. To include a template file, use:
[["path/template.tpl"]]
You can also set and display variables:
[[title = "Page title"]]
<h1>[[title]]</h1>
If a PHP code block is enclosed in double square brackets, it will be executed when the page is cached and its output is stored as static HTML. It can also use TACS variables – just add a $ to the variable name, e.g.
[[title = "Page title"]]
<-- cache the following output as static HTML -->
[[<?php
echo "<h1>$title</h1>";
?>]]
(Note that PHP code in the main file that has the require_once are always cached whether it is enclosed in square brackets or not).
Finally, normal PHP within included files is run every time the page is loaded, e.g.
<?php
echo date('Y-m-d H:i:s');
?>
We use TACS for many of our sites. Pages can be developed quicker, the code is cleaner, they are easier to maintain, and downloading is faster.
Interested?… Download TACS (12 Kb). You are free to use, modify, or distribute the software. An acknowledgment and link back to optimalworks.net is all we ask, but feel free to make a donation!
- categories: free download, php
- trackback: http://www.optimalworks.net/blog/2007/software/free-download/tacs-php-template/trackback
- bookmark: del.icio.us, digg, facebook, twitter, reddit, Furl, Spurl, Blinklist, Slashdot, Technorati, Yahoo!