Note:

How Templeet works

Explanation for beginners

Templeet is complete language. It associates called URLs with templates. These templates can be simple HTML pages containing or not Templeet function calls. More generally pages created with Templeet can be of any text format such as SVG, SMIL, TXT, etc...

By default, for any requested page Templeet will use the same filename as template. If mypage.html is called, Templeet will try to use in this order the first template found in template/mypage.tmpl and template/mypage.html. If none is found a 404 error will be returned.

You can easily pass parameters to templates by adding them after the filename and separated by comas. When calling mypage,param1,param2.html Templeet will use the same template as in the previous example. You can retrieve parameters in your templates with the module filename.

Explanation for experienced users

As previously indicated, Templeet associates requested pages with their template. You may also want to associate different URLs with one template. Then you have to fill in an array in the templeet/config.php file with a PERL regular expression matching URLs and a corresponding template. In the following example Templeet associates all HTML pages containing only a number (1.html, 2.html, etc) with one template (template/montemplate.html).

Note : Apart from exceptions you should not remove default entries. Add yours after the default ones.

    $config['html2template_array'] = array(
	    '|^templeet_doc/.+\.(:?\w{2})?html$|'=>'template/doc.tmpl',
	    '|^([^,]+).*\.html$|'		    =>'template/\1.tmpl',
	    '|^([^,]+).*\.(?:\w{2}\.)?([^\.]+)$|'   =>'template/\1.\2',

	    '|\d+\.html$|' => 'template/mytemplate.html',  // example 
    );

Template syntax

Templates are text files with Templeet commands. The files may be in HTML, SVG, SMIL, etc. Templeet is able to generate any format as soon as it is a text based format.

Templeet commands begin with a ~ character, followed by the function name, an opening parenthese, optional arguments separated by commas, and a closing parenthese. Function names may contain alphanumeric character, and '_'.

This is a template used for ~get_filename()

~set('count',1)
~while(~get('count')<=3,
  'I count ~get('count')
~set('count',~get('count')+1)')

If this template is "template/foo.tmpl" then a call to "templeet.php?/foo.html" would give the following. Functions will be detailed later, don't try to understand them, look only at the syntax for the moment.

This is a template used for foo

I count 1
I count 2
I count 3

In this example, the "set" function puts the second argument into a variable which name is the first argument. The "while" function evaluate the second arguments as long as the first one returns true. The "get" function returns the variable's information. The "get_filename" function doesn't take any arguments, it just returns the name of the requested file, without its extension.

The language system

Templeet allows you to create multi-lingual pages. The system is similar to the MultiViews system used in Apache, and is fully compatible.

Once Templeet has chosen which template to use, it then looks for the template in the requested language by the user's browser. If it exists, it uses it, if not it looks for the default template set up into the config.php file. If it doesn't exist template without any language is used. If nothing exists, it returns a 404 error, and uses the "template/error/404.tmpl" template.

So, if "templeet.php?/index.html" is requested from a French browser, and the default language into the config.php file is English, it will use the first exsiting template among:

Available functions

Templeet is built in a way to make the smallest possible code in the core part. The addition of facultative modules offer sets of functions.

Your system currently contains the following modules:

.core : Basic Templeet's functions
.array : array and list management
.auth : Authentication
.authedit : Authentication management
.binoperator : binary operators
.cache : cache management, cache deletion and expiration
.configurator
.convpassfile
.cryptedimage
.cuthtml : text extraction from string containing HTML
.debug
.defunc : function creation
.detar
.diff
.dir : directory management
.fieldfileaccess
.filearray
.filename : management of parameters passed in url
.filesystem
.getglobals : management of server variables, environment, session, cookies and GET and POST parameters
.html : HTML string management
.image
.ip : IP address management
.ldap
.lines : text management line by line
.list : databases access (mysql, pgsql,...)
.list_tree
.ls : directory and file management
.package
.passthru
.rand : rand functions
.rdf : external RDF file management
.redirect : URL redirect
.regex : regular expressions
.session
.setlocal
.spell : spell checking
.strings : string management
.time : date functions
.treewalk
.url : local url management

Optimization

This is the configuration which gets the best possible performances from Templeet. They are similar to performances with static pages.

  • The best commonly usable configuration corresponds to the activation of all caches of Templeet with http 403 and 404 errors managament. .htaccess file thus contains:
    	ErrorDocument 403 /templeet.php
    	ErrorDocument 404 /templeet.php
    	Options -Indexes
    	
  • It's still possible to gain a bit by moving these directives to apache configuration file and by blocking the reading of .htaccess file with:
    	AllowOverride None
    	
  • Disabling DNS resolutions in Apache will gain a bit more:
    	HostnameLookups Off
    	

Wiki

You may find additional help in the Templeet documentation wiki.