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.
- ˜include : To include a file or template.
- ˜eval : To evaluate some Templeet code.
- ˜if : To make a test.
- ˜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
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
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
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.0503
Back to top