Note:
The core section is the part that contains the minimum vital functions to make Templeet work.
The following functions are available:
- set and get : To set and get a variable.
- rem : To insert a comment in Templeet code.
- noeval : To insert a comment in Templeet code with no evaluation.
- include : To include a file or template.
- eval : To evaluate some Templeet code.
- if : To make a test.
- switch : To make multiple tests.
- while : To loop.
- empty : To test argument emptyness.
- equal : To test arguments equality.
- notequal : To test arguments inequality.
- and : Logical AND.
- executedtime
set and get
These functions are used to handle variables. ~set() takes 2 arguments, the variable name and the value to set the variable. ~get() takes only one argument which is the name of the variable to get the value.~set('myvariable', 'I\'m a test') ~get('myvariable') => I'm a test
The following variable are set by Templeet, do not reuse them :
~get('path') => templeet_doc/core.en.html ~get('template') => template/doc.en.html ~get('lang') => en ~get('templatedir') => template/ ~get('actual_template') => template/templeet_doc/core.en.html
Back to top
rem
This function allows you to comment your code.Thou Shalt Comment Your Code.
~rem("The approach is a bit ugly but it works...")
Back to top
noeval
This function allows you to comment your code. This function is similar to rem but no evaluation occur.~noeval("this code is not executed ")
Back to top
include
The include function allows to include a file or an other template. Path is relative to the current template directory.Some parameters can be passed to ~include() function. They can be retrieved in the included template with the ~parseparam() function.
~include('file.txt',"1st parameter", 10)
When that function is used in the "template/example.tmpl" template then "template/file.txt" will be included. It can itself contain Templeet functions. Parameters set in the include function can be retrieved. For example ~parseparam(1) returns "1st parameter" (whitout the double quotes) and ~parseparam(2) returns "10".
Back to top
eval
This function evaluates some Templeet code. Thus, a template can dynamically generate some code and set into a variable to be evaluated later.~eval('~set('foo',10) ~get('foo')')
That command sets "10" to variable "foo", and returns the content of that same variable.
Back to top
if
The if function makes a test. If the first parameter is true then evaluation of the second parameter is returned, else, if it exists, the evaluation of the third parameter is returned.~if(1<2,"It's true!","It's false!")
Previous example returns "It's true!".
Back to top
switch
The switch function makes a serie of tests. Arguments are given by pairs. The first of a pair is a test while the second is the value to return if the test is true. The switch evaluation stops at the first test returning "true". If all tests return "false" it's possible to return a default value by appending it as the last argument of the switch function call.~set('x',1) ~switch( ~get('x')<0,"x is negative", ~get('x')>0,"x is positive", "x is null")
Previous example returns "x is positive".
Back to top
while
It evaluates the second parameter while the first evaluates to true.~set('counter',1) ~while(~get('counter')<=3, 'we count ... ~get('counter')<br/> ~set('counter',~get('counter')+1)')
we count ... 1
we count ... 2
we count ... 3
Back to top
Logical AND
~and(2,3) => 1 ~and(0,3) =>
Back to top
executedtime
This function returns the time taken in seconds for template evaluation. It doesn't take any parameters.~executedtime() => 0.0474
Back to top