lilTC - a 'little' template class - documentation 2008-01-20 - Christian Doebler Table of contents ================== 1. Copyright 2. Preface 3. Installation 4. Configuration 5. Methods 1. Copyright ============= This software is Copyright (c) 2008 Christian Doebler (Except where explicitly superseded by other copyright notices) LICENSE: This work is made available to you under the terms of Version 2 of the GNU General Public License. A copy of that license should have been provided with this software, but in any event can be snarfed from http://www.fsf.org. This work is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 or visit their web page on the internet at http://www.fsf.org. CONTRIBUTION SUBMISSION POLICY: (The following paragraph is not intended to limit the rights granted to you to modify and distribute this software under the terms of the GNU General Public License and is only of importance to you if you choose to contribute your changes and enhancements to the community by submitting them to Christian Doebler.) By intentionally submitting any modifications, corrections or derivatives to this work, or any other work intended for use with this Software, to Christian Doebler, you confirm that you are the copyright holder for those contributions and you grant Christian Doebler a nonexclusive, worldwide, irrevocable, royalty-free, perpetual, license to use, copy, create derivative works based on those contributions, and sublicense and distribute those contributions and any derivatives thereof. 2. Preface ============ lilTC, which stands for "a 'little' template class" is a class, written in PHP which can be used for filling any kind of templates with dynamic data. Usually this class is used for HTML pages. lilTC is very easy to install and to use and it supports file caching to shorten the time until the document can be seen in a browser. Why another template tool? Simply, because the other tools are way too overloaded for my needs. 3. Installation ================= Simply copy the class file 'class_lilTC.php' to a folder of your choice, which you can read from as httpd user. E.g.: /var/www/your_site/htdocs/classes. Now, you only have to include the class in a PHP file: include_once('/class_lilTC.php'); 4. Configuration ================= In most of the cases, there is no need for configuration but you might get to know, how you can customise the behaviour of the template class. Configuration is done in the header of the class. Here is a list of the variables you might want to alter. private $cache = false; set this to true if you want to enable caching by default private $cacheDir = ''; define the directory, where the class should store the cache files private $cacheFileSuffix = '_lilTC'; to make the identification of cache files easier, they are suffixed change this value if you want any other or maybe no suffix at all private $warnOnUnsetVars = false; set to true, this setting enables warning messages, when a variable, which has been defined in your page, has not been assigned these errors are displayed, while the parsing process is running private $warnOnCacheFile = false; set to true, this setting enables warning messages because of problems while reading cache files private $warnOnTemplateFile = false; set to true, this setting enables warning messages because of problems while reading template files 5. Methods =========== Here, the methods are described, which you can use to generate your dynamic pages. lilTC($file, $cache) This is the constructor method. The parameters are optional. $file : The template file to use for page generation. $cache : Enable/disable caching. Values: true | false. This gives you the possibility to override your global cache settings as set up in the class header Example: $template = new lilTC('templates/index.html'); assign($variable, $data) This method assigns the data, stored in $data, to the variable, named as the value in $variable, of course. The variable name should be somewhere in your template file. Example: $template->assign('GREETING', 'Welcome'); If you want the class to work properly, you have to set variables in your template like this: {$VARIABLE_NAME} Example:

{$GREETING}

setTemplate($file) With this method, you can set the template file if have not already done so at initialisation, via ... = new lilTC($file ... Example: $template->setTemplate('templates/index.html'); getHTML() This method tries to parse the HTML code and lets generate the cache file if caching is enabled. It returns your ready-to-send HTML code in a string. Example: $content = $template->getHTML(); show() This method also tries to parse the HTML code and also triggers the generation of a cache file if set. The difference to 'getHTML' is, that the content will be displayed directly. Example: $template->show(); enableCache() Guess what... with this method you can enable caching. Example: $template->enableCache(); disableCache() That one had to come, since you can enable the cache. Right, this method is used to disable the file caching. Example: $template->disableCache(); clearCache() Use this method to delete your cache file. It returns true on success and false on error(s). Example: $template->clearCache(); checkCache() With this method you can check whether a cache file exists. It returns true if the cache file has been found and false on error(s). Example: $cacheAvailable = $template->checkChache(); preParse() Usually, you only can parse once. With this method, you can pre-parse your code. Only assigned values will be substituted. This is helpful when you want to assign some variables dynamically to your template. Example: $template->preParse(); bulkAssign($assign, $file) With this method, you can assign several values at once. The $file is optional. When you set this properly to a file, holding your definitions, this file will be included to get all the data that has to be assigned. This might be helpful when you use language files. The data od $assign depends on $file. When $file has been set, $assign needs to be a normal array, holding all the variables of your template to be assigned. When $file has not been set, $array needs to be an associative array, where the keys are the variable names of your template and the corresponding values are the data, which should be assigned. Examples: $assign = array('GREETING', 'TITLE'); $file = 'language/en/frontpage.php'; $template->bulkAssign($assign, $file); $assign = array( 'GREETING' => 'Welcome!', 'TITLE' => 'MySite', ); $template->bulkassign($assign); That's it. Have a look at the example file in the directory 'example', if you want to see how the class can be used. Have fun. # EOF