Download FAQ
 

the module core returns is the only module necessary for the correct operation of Templeet. It integrates the basic functions.

the following functions are available:



blocks of instructions

quotes and double quotes :

In Templeet language quotes ' or double quotes " bound character strings. Templeet instructions being interpreted in strings, these can be used to delimit blocks of instructions. For example :

~if(10>1,
	'Here first block delimited by quotes
	~if(~empty(~get("foo")), 
		~set("foo", 10),
		"Another block delimited by double quotes"
	)
	',
	'Here second block delimited by quotes'
)

Bloc <![nomdubloc[ ... ]nomdubloc]> :

However, when you have to implement more complex algorithms which require several imbricated conditions, it becomes difficult to locate the beginning and the end of a block.
to face this problem you can use another syntax to delimit blocks : <![nomdubloc[ ... ]nomdubloc]>.

Example :

~if(10>1,
	<![bloc1[
	This is the first block named "block1"
	~if(~empty(~get("foo")),
		~set("foo", 10),
		<![foo[ Another block named "foo" ]foo]>
	)
	]bloc1]>,
	<![foo[ Yet another block named "foo" ]foo]>
)

braces { and } :

blocks defined by braces have a particular operation.

instructions are separated by comas ", ". For example see below :

{
	~set("i", 2),
	~set("j", 3),
	~get("j"),
	~plus(~get("j"), ~get("j"))
}

this script will return :

5

As you can notice, value 3 returned by ~get("j") is silently ignored. Only the last block of instruction is returned.



"true" comments

It is possible to integrate comments in your scripts whose contents will not be treated by Templeet (contrary to the order ~rem())

For that it is necessary is to use the characters // or the block /* ... */ inside an instruction Templeet.

Example :

~string(
// This is a one line comment

/*
This is a block type comment
*/
)

Another example :

~rem(
// This is a one line comment

/*
This is a block type comment
*/
)


set and get

These functions are used to handle variables. The ~set() function takes 2 arguments, the name of the variable and the contents of the variable. The ~get() function as for it takes one argument, the name of the variable to recover.

~set('myvariable', 'I\'m a test')		 

~get('myvariable')				=>	I'm a test

the example uses these two functions in order to handle tables :

~set('tab[1]', 'value1')	       
~set('tab[2]', 'value2')	       
~set('tab[3]', 'value3')	       

~get('tab[1]')				=>	value1
~get('tab[2]')				=>	value2
~get('tab[3]')				=>	value3

the ~set function also makes it possible to destroy a variable :

~set('myvariable', 'I\'m a test')	 

~get('myvariable')			=> I'm a test

~set('myvariable')			

~get('myvariable')			=> 


~set('tab[1]', 'value1')	       
~set('tab[2]', 'value2')	       
~set('tab[3]', 'value3')	       

~get('tab[1]')				=>	value1
~get('tab[2]')				=>	value2
~get('tab[3]')				=>	value3

~set('tab[2]')		

~get('tab[1]')				=>	value1
~get('tab[2]')				=>	
~get('tab[3]')				=>	value3

~set('tab')		

~get('tab[1]')				=>	
~get('tab[2]')				=>	
~get('tab[3]')				=>	

the following variables are defined by Templeet, do not re-use them :

~get('path')     => templeet_doc/core.html.en
~get('template') => template/templeet_doc/$html.tmpl
~get('lang')     => en
~get('templatedir')	      => 
~get('actual_template')  => template/templeet_doc/en/core.tmpl

array

This function makes it possible to create a table of figures.

Example of usage :

~set("tab",
	~array(
		"foo"=>1,
		"bar"=>2
	)
)

~get("tab[foo]") --> 1
~get("tab[bar]") --> 2

rem

This function makes it possible to comment on its code, and thou shalt comment your code (tm)

~rem("it is a little rough approach but that being supposed to go...")

noeval

This function makes it possible to comment on its code without evaluation.

~noeval("this code is not evaluated  ")

include and parseparam

This function makes it possible to include a file or another template. By default it uses the repertory of the template father.

Of the arguments can have placed to the ~include() order, and they can be used in the template included thanks to the order ~parseparam().

Example :

Content of file "index.html" :

~include('file.txt',"1st argument", 10)

Content of file "file.txt" :

the first argument is: ~parseparam(1) the second argument is : ~parseparam(2)

Result of script "index.html" :

the first argument is: 1st argument the second argument is: 10

If this order is used in the template "template/example.tmpl" then the file "template/file.txt" will be included. This template can comprise Templeet orders. It will be able to recover the arguments passed at the time of the include. For example ~parseparam(1) will turn over "1st argument" (without the "), and ~parseparam(2) will turn over" 10" (without the ").

eval

This function makes it possible to evaluate Templeet code. Thus Templeet code can be generated dynamically in a variable, then evaluated later.

~eval('~set('foo',10) ~get('foo')')

This order will put "10" in the variable "foo", then will turn over the contents of this same variable.

if

This order carries out a conditional test, evaluates the 2nd argument if the test turns over true, if not and if there exists, evaluates the 3rd argument.

~if(1<2,"it is true!","it is false!")

the preceding example will turn over it is true! .

switch

This order carries out a series The arguments passed two by two. The first of a pair is a test, the second is the value to be returned if the test is true. The evaluation of switch stops with the first test which turns over true. It is possible to return a default value if all the tests failed, it is enough to put it as last argument.

~set('x',1)
~switch(
	~get('x')<0,"x is negative",
	~get('x')>0,"x is positive",
	"x is null")

the preceding example will turn over "x is positive".

while

This order takes 2 arguments, it evaluates 2nd as long as 1st true.

~set('counter',1)
~while(~get('counter')<=3,
	'one turns over counts ... ~get('counter')
	~set('counter',~get('counter')+1)')

for

This order takes 4 arguments, it evaluates 4th as long as 2nd turns over true. The first argument is the code of initialization, 3rd that of incrementing.

~for(~set('counter',1),~get('counter')<=3,~set('counter',~get('counter')+1),
	'I count ... ~get('counter')'
)
=>

I count ... 1I count ... 2I count ... 3

empty

Returns 1 if the argument is empty, 0 if not.

~empty(~get('trick')) =>	0
~set('trick','something')~empty(~get('trick'))  =>	 0

plus minus multiple et divide

These functions are not used in normal time since one can use the traditional arithmetic writing.

~plus(2,3)			=>	5

~minus(3,5)			=>	-2

~multiple(3,5)			=>	15

~divide(8,3)			=>	2.66666666667

inc dec

the ~inc function increments the variable provided in parameter. Example :

~set("i", 1)
~inc("i")
~get("i") => 2

the function ~dec decrements variable provided in parameter. Example :

~set("i", 2)
~dec("i")
~get("i") => 1

integer

This function is used to force the type of an argument to (int). For the round-offs by values lower and higher and truncations, think of functions PHP: floor, ceil and round.

~divide(8,3)			=>	2.66666666667

~integer(~divide(8,3))			=>	2

~ceil(~divide(8,3))			=>	3

equal notequal sup inf infequal supequal

These functions are not normaly used since traditional writing can be used ( ==, !=, >, < >=, <=).

~inf(2,2)			=>	0
~infequal(2,2)			=>	1

~sup(3,3)			=>	0
~supequal(3,3)			=>	1

~equal(3,5)			=>	0
~equal(3,3)			=>	1

~notequal(8,3)			=>	1
~notequal(8,8)			=>	0

executedtime

This function, which takes no argument, returns time used to execute the template.

~executedtime()			=>	0.094