About Templeet
Templeet works as follow. It analyzes the url requested by the internet user, looks if a template exists for that url, and if so evaluates the template. An array is used to associate urls with templates. Its name is $config['html2template_array'] in the config.php file.
$config['html2template_array'] = array(
'/^example\.html$/'=>'template/example.tmpl',
'/^news\/\d+\.html$/'=>'template/news.tmpl');
In this example, the url "templeet.php?/example.html" will use the template "template/example.tmpl", and every page which looks like "templeet.php?/news/X.html" with X being a number will use "template/news.tmpl". The regex uses PCRE, you can check the online documentation. You can also use expressions like '/^news\/(\d+).html$/'=>'template/\1.tmpl' so when "/news/10.html" is asked, "template/10.tmpl", if it exists, will be used.
Note : You must call every page through the file templeet.php which runs Templeet. You can use "templeet.php?/page.html" or "templeet.php/page.html", it's up to you. However, to prevent this, you can add the following like to your Apache configuration, or into a .htaccess file if you have permissions to do so. You will then be able to call "/page.html" directly.
ErrorDocument 404 /templeet.php
Templates 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:
- template/index.fr.tmpl
- template/index.en.tmpl
- template/index.tmpl
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:
- auth
- authedit
- binoperator
- cache
- cuthtml
- defunc
- dir
- filename
- getglobals
- html
- ip
- lines
- list
- list_mysql
- list_pgsql
- ls
- rand
- rdf
- readfile
- redirect
- regex
- strings
- time
- url
- writefile
Optimization
This is the configuration which gets the best possible performances from Templeet. They are similar to performances with static pages.
- Activate every cache in Templeet in the config.php file
- Let $config['pagecachedir'] be the same as DocumentRoot
- Add theses lines into the Apache configuration file, with templeet-root as the directory of Templeet:
Alias /templeet.php templeet-root/src/htdocs/templeet.php ErrorDocument 403 /templeet.php ErrorDocument 404 /templeet.php
- Remove the .htaccess file system:
AllowOverride None
- Remove the DNS lookups:
HostnameLookups Off