|
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*
TinyButStrong Documentationversion 3.7
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* |
|||||||
Template Engine for Pro and Beginners for PHP 5 |
Table of Contents:
Introduction:
TinyButStrong (TBS) is a PHP class useful to develop an application in a clean way, separating PHP scripts and XML/HTML/Text files. With TBS, the files are generated dynamically by merging a template with data. It is called a Template Engine.The name TBS comes from the fact that this tool contains only 8 functions and yet, it is very powerful. It allows you to merge templates with your PHP variables or your MySQL, PostgreSQL, or SQLite.
TBS has been engineered so that you can develop your templates with ease using any visual editors (like Dreamweaver or FrontPage). But if you are used to designing your templates with a text editor, it is nice as well. TBS also enables you to create JavaScript dynamically.
As the name of it tells, TBS is easy to use, strong and fast. It is completely °~° freeware °~°.
Basic principles:
On the HTML side (or other file type):You design a page which does not necessarily contain any PHP scripts, nor any programming. In this page you place TBS tags in the places where you want to display the dynamic data. This page is called a 'template'.
There are two types of tags: the 'fields' which are used to display dynamic data items, and the 'blocks' which are used to define an area, mostly in order to display records from a data source.
On the PHP side:
You use an object TBS variable to manage the merge of your template with the data. At the end, TBS shows the result of the merge.
Installation:
| 1. | Copy the file tbs_class.php in a directory of your Web site. |
| 2. | At the beginning of your PHP program, add the lines: include_once('tbs_class.php'); $TBS =& new clsTinyButStrong; Remark: if the TBS file tbs_class.php is in a different directory than your application, then you have to precise the directory in front of the TBS file name. |
Explanations and technical details:
TinyButStrong is a library written in PHP, it's a component to be referenced in your own PHP programs. In technical terms, TinyButStrong is a PHP 'class' ; the name of this class is clsTinyButStrong.
The variable $TBS that you add at the beginning of your PHP program enables you to execute the merge of your template from your PHP application. In technical terms, the variable $TBS is an 'instance' of the clsTinyButStrong class.
Mini examples:
Example 1:| Html Template | Php Program | Result |
|   [onshow.message]   |
<? include_once('tbs_class.php'); $TBS =& new clsTinyButStrong; $TBS->LoadTemplate('template.htm'); $message = 'Hello'; $TBS->Show(); ?> |
  Hello   |
Example 2:
| Html Template | Php Program | Result |
|

[blk.val;block=tr]

 |
<? include_once('tbs_class.php'); $TBS =& new clsTinyButStrong; $TBS->LoadTemplate('template.htm'); $list = array('X','Y','Z'); $TBS->MergeBlock('blk', $list); $TBS->Show(); ?> |

X

Y

Z

 |
PHP side:
The merging of a template is done in a PHP program using an object variable declared as a clsTinyButStrong class.Example of statement: $TBS = new clsTinyButStrong;
This object allows you to load a template, to handle the merging of it with data, and then to show the result.
Example of PHP code:
include_once('tbs_class.php');
$TBS =& new clsTinyButStrong;
$TBS->LoadTemplate('template.htm') ;
$TBS->MergeBlock('ctry','mysql','SELECT * FROM t_country');
$TBS->Show();
$TBS =& new clsTinyButStrong;
$TBS->LoadTemplate('template.htm') ;
$TBS->MergeBlock('ctry','mysql','SELECT * FROM t_country');
$TBS->Show();
Here is the description of the TinyButStrong object:
create a new TBS object:
A TBS object is created as a new instance of the clsTinyButStrong class. A TBS object enables you to work with one or several templates using the object's methods and properties.
Syntax to create a new TBS object: $TBS = new clsTinyButStrong({string TagDelim {, string VarPrefix {, string FctPrefix}}})
Examples:
Syntax to create a new TBS object: $TBS = new clsTinyButStrong({string TagDelim {, string VarPrefix {, string FctPrefix}}})
| Argument | Description |
| TagDelim | Define the couple of delimiters for TBS tags recognized in templates. The default value is '' (empty string) which means the default TBS delimiters. That is '[' and ']'. Example: if you want to have the delimiters to be {{ and }} for TBS fields, then set TagDelim to the value '{{,}}'. Thus TBS fields will be like {{var.x}} instead of [var.x]. It's recommended to let the default TBS delimiters, while changing them is working well. Default TBS delimiters are [ and ] because those characters are usable quite everywhere in XML/HTML documents, and they are located faster than delimiters { / } or ( / ) since they are rarer, especially in HTML. |
| VarPrefix | Limit the usage of automatic fields ([onload] [onshow] and [var]) in templates. TBS will display only global PHP variables prefixed with VarPrefix. Other variables will produce an error message. The default for VarPrefix value is '' (empty string) which means no limitation. |
| FctPrefix | Limit the usage of custom PHP functions (relative to parameters onformat and ondata) in templates. TBS will call only PHP function prefixed with FctPrefix. Other functions will produce an error message. The default value is '' (empty string) which means no limitation. This argument is supported since TBS version 3.6.0. |
Examples:
$TBS1 = new clsTinyButStrong; // default behavior
$TBS2 = new clsTinyButStrong('{{,}}'); // TBS tags will be like {{var.x}} instead of [var.x]
$TBS3 = new clsTinyButStrong('', 'tbs_var_'); // TBS will display only PHP global variables beginning with 'tbs_var_'
$TBS4 = new clsTinyButStrong('', '', 'tbs_fct_');// TBS will call only PHP function beginning with 'tbs_fct_'
$TBS2 = new clsTinyButStrong('{{,}}'); // TBS tags will be like {{var.x}} instead of [var.x]
$TBS3 = new clsTinyButStrong('', 'tbs_var_'); // TBS will display only PHP global variables beginning with 'tbs_var_'
$TBS4 = new clsTinyButStrong('', '', 'tbs_fct_');// TBS will call only PHP function beginning with 'tbs_fct_'
method LoadTemplate():
Loads a template for the merging process.
The complete contents of the file is immediately stored in the Source property of the TBS object, then [onload] fields and blocks are merged.
If the file is not found, then it will also be searched in the folder of the last loaded template (since TBS version 3.2.0).
Syntax: $TBS->LoadTemplate(string File{, string Charset})
Scope of the file path:
If the file is nout found then its' also searched into the directory of the last loaded template, or the last loaded subtemplate.
Since TBS version 3.3.0, the file also searched into the include_path.
No character conversion:
If you use value False as the argument Charset, data will to not be converted when merged into the model.
Note that parameters htmlconv can be use to define the conversion of special characters for one TBS field only.
User function:
If your charset is not yet supported by PHP, you can indicate a user function that will perform the conversion of special characters. For this, use the argument Charset with the syntax '=myfunction'.
Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).
Since TBS version 3.3.0, such a custom function should have a second argument for line break conversion.
Since TBS version 3.5.0, argument Charset can also be an array containing an object and a method. Example: array(&$obj, 'mymethod').
Here is an example which gives the expected syntaxe:
Adding the file at the end of the current template:
You can use the keyword '+' for the argument Charset to have the file defined by File added to the end of the current template. The current charset will not be modified.
Special actions using argument File:
Since TBS version 3.4.0.
If File is null, then all default actions (Plug-ins, [onload] tags, and Charset) are applied without loading any file.
If File is '' (empty string), then only the charset is modified, without doing any other action.
In both cases, if Charset is '+', then it will be ignored and the current charset will not be modified.
Example:
The complete contents of the file is immediately stored in the Source property of the TBS object, then [onload] fields and blocks are merged.
If the file is not found, then it will also be searched in the folder of the last loaded template (since TBS version 3.2.0).
Syntax: $TBS->LoadTemplate(string File{, string Charset})
| Argument | Description |
| File | Local or absolute path of the file to load. This value can be null or '' (empty string) for special actions. See below for more details. |
| Charset | Optional. Indicates the character encoding (charset) to use for conversion of special characters when data will be merged. It should be the same as the charset of the template. The default value is '' (empty string) which is equivalent to 'ISO-8859-1' (Latin 1). If your template uses a special charset, then indicate the Html value for this charset. In a Html page, the charset is placed at the beginning of the file, in the attribute 'content' of a <Meta> tag. The charsets supported by TBS are the charsets supported by the PHP function htmlentities(). For example: 'BIG5' (Chinese) or 'EUCJP' (Japanese). See below for more possibilities. |
Scope of the file path:
If the file is nout found then its' also searched into the directory of the last loaded template, or the last loaded subtemplate.
Since TBS version 3.3.0, the file also searched into the include_path.
No character conversion:
If you use value False as the argument Charset, data will to not be converted when merged into the model.
Note that parameters htmlconv can be use to define the conversion of special characters for one TBS field only.
User function:
If your charset is not yet supported by PHP, you can indicate a user function that will perform the conversion of special characters. For this, use the argument Charset with the syntax '=myfunction'.
Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).
Since TBS version 3.3.0, such a custom function should have a second argument for line break conversion.
Since TBS version 3.5.0, argument Charset can also be an array containing an object and a method. Example: array(&$obj, 'mymethod').
Here is an example which gives the expected syntaxe:
function f_StrToXml($Txt string,$ConvBr boolean) {
// Convert a string into an XML text.
$x = htmlspecialchars(utf8_encode($Txt));
if ($ConvBr) {
$x = nl2br($x); // Convert any type of line break
$x = str_replace('
', '<text:line-break/>',$x);
return $x;
}
// Convert a string into an XML text.
$x = htmlspecialchars(utf8_encode($Txt));
if ($ConvBr) {
$x = nl2br($x); // Convert any type of line break
$x = str_replace('
', '<text:line-break/>',$x);
return $x;
}
Adding the file at the end of the current template:
You can use the keyword '+' for the argument Charset to have the file defined by File added to the end of the current template. The current charset will not be modified.
Special actions using argument File:
Since TBS version 3.4.0.
If File is null, then all default actions (Plug-ins, [onload] tags, and Charset) are applied without loading any file.
If File is '' (empty string), then only the charset is modified, without doing any other action.
In both cases, if Charset is '+', then it will be ignored and the current charset will not be modified.
Example:
$TBS->Source = $template; // load the template from a string
$TBS->LoadTemplate(null,'BIG5'); // run plug-ins if any, and merges [onload] tags if any
...
$TBS->LoadTemplate('',false); // turn the charset to no-charset
$TBS->LoadTemplate(null,'BIG5'); // run plug-ins if any, and merges [onload] tags if any
...
$TBS->LoadTemplate('',false); // turn the charset to no-charset
method MergeBlock():
Merges one or several TBS blocks with records coming from a data source.
by default, this method returns the number of merged records (more exactly, it is the number of the last record), but it can also return the full merged record set (see argument BlockName).
TinyButStrong supports several data source types in native:
Php data: an array, a string, a number.
Databases: MySQL ; PostgreSQL ; SQLite.
You can also add a new one: 'database plug-ins'.
Syntax: int $TBS->MergeBlock(string BlockName, mixed Source{, string Query}{, mixed QryPrms})
Link between the block and the records:
Merging several blocks with the same data:
You can merge several blocks with the same data by indicating their names separated by commas in the BlockName parameter. In this case, the query is opened only one time, and records are buffered to feed blocks.
Example: $TBS->MergeBlock('block1,block2,block3','mysql','SELECT * FROM MyTable');
You cannot merge several blocks having the same names because they are considered by TBS has a one and only block composed of several sections. Nevertheless, you can use a tip to get a similar behavior. If you use parameter p1 without value in the block definition, that does forces TBS to consider the section as a new block break, like it does for subblocks.
Example:
$TBS->MergeBlock('b','mysql','SELECT * FROM MyTable');
Returning the full merged record set:
In some cases, it may be useful for you to retrieve the full record set after the merge. For that, you simply have to ad the keyword '*' in the list of block's names. Use this feature with care, because it save the merged data in the memory which can take resources.
Example: $data = $TBS->MergeBlock('block1,*','mysql','SELECT * FROM MaTable');
Counting the records:
To display the number of the record in the template, use a TBS Field linked to the virtual column '#'. If you put this field outside the block, it will display the total number of records.
Example: [block1.#]
The virtual column '$' will display the key of the current record if the data source is a Php array.
Example: [block1.$]
Resource and Request arguments according to the data source type:
(*) See explanations in the chapter below.
by default, this method returns the number of merged records (more exactly, it is the number of the last record), but it can also return the full merged record set (see argument BlockName).
TinyButStrong supports several data source types in native:
Php data: an array, a string, a number.
Databases: MySQL ; PostgreSQL ; SQLite.
You can also add a new one: 'database plug-ins'.
Syntax: int $TBS->MergeBlock(string BlockName, mixed Source{, string Query}{, mixed QryPrms})
| Argument | Description |
| BlockName | Indicates the name of the TBS block to merge. You can merge several blocks with the same data by indicating their names separated by commas. If you add '*' as a block name, then the method will return the full merged record set as a PHP array, instead of the number of records. Versioning: the keyword '*' is supported since TBS version 3.0. |
| Source | Indicates the data source to merge. |
| Query | Optional. Indicates the SQL statement which returns the records to merge. The table below shows the possible values according to the data source type. |
| QryPrms | Optional. Extra parameters for the query. Few data source types are taking this argument in account. Versioning: the argument QryPrms is supported since TBS version 3.7.0. |
Link between the block and the records:
The MergeBlock() method searches in your template for the specified TBS block name. Then, the block is repeated as many times as there are records in the data source.
To display the data of a record, you have to use a linked TBS Field. A TBS Field is linked when the name of it is composed of the block's name followed by a dot and a column's or a key's name in the record set. A linked field must be inside the block.
Example:
If no block's definition is found in the template, then the MergeBlock() method will merge the first record with all linked fields found in the template.
You can also define more advanced blocks. For more information, refer to chapter TBS Blocks.
To display the data of a record, you have to use a linked TBS Field. A TBS Field is linked when the name of it is composed of the block's name followed by a dot and a column's or a key's name in the record set. A linked field must be inside the block.
Example:
Block's name: block1
Columns returned by the query: field1,field2,field3
Linked TBS Fields: [block1.field1], [block1.field2], [block1.field3]
Columns returned by the query: field1,field2,field3
Linked TBS Fields: [block1.field1], [block1.field2], [block1.field3]
If no block's definition is found in the template, then the MergeBlock() method will merge the first record with all linked fields found in the template.
You can also define more advanced blocks. For more information, refer to chapter TBS Blocks.
Merging several blocks with the same data:
You can merge several blocks with the same data by indicating their names separated by commas in the BlockName parameter. In this case, the query is opened only one time, and records are buffered to feed blocks.
Example: $TBS->MergeBlock('block1,block2,block3','mysql','SELECT * FROM MyTable');
You cannot merge several blocks having the same names because they are considered by TBS has a one and only block composed of several sections. Nevertheless, you can use a tip to get a similar behavior. If you use parameter p1 without value in the block definition, that does forces TBS to consider the section as a new block break, like it does for subblocks.
Example:
|
|
$TBS->MergeBlock('b','mysql','SELECT * FROM MyTable');
Versioning: this tip is available since TBS version 3.4.
Returning the full merged record set:
In some cases, it may be useful for you to retrieve the full record set after the merge. For that, you simply have to ad the keyword '*' in the list of block's names. Use this feature with care, because it save the merged data in the memory which can take resources.
Example: $data = $TBS->MergeBlock('block1,*','mysql','SELECT * FROM MaTable');
Counting the records:
To display the number of the record in the template, use a TBS Field linked to the virtual column '#'. If you put this field outside the block, it will display the total number of records.
Example: [block1.#]
The virtual column '$' will display the key of the current record if the data source is a Php array.
Example: [block1.$]
Resource and Request arguments according to the data source type:
| Data Source Type | Source | Query |
| Assigned (*) | The keyword 'assigned' or omitted | - |
| Text (*) | The keyword 'text' | A text |
| Number (*) | The keyword 'num' | A number or a special array (see below) |
| Clear (*) | The keyword 'clear' | - |
| Conditional (*) | The keyword 'cond' | - |
| PHP Array (*) | A Php array | - |
| The keyword 'array' | A Php Array | |
| The keyword 'array' | A string that represents an array contained or nested in a PHP global variable (see below) | |
| PHP ArrayObject | A PHP object. Supported since TBS version 3.5.0. | - |
| PHP Iterator | ||
| PHP IteratorAggregate | ||
| PDO | A PDO object. Supported since TBS version 3.7.0. | An SQL statement. Optional argument QryPrms can be used like with PDOStatement->execute(QryPrms). |
| MySQLi | A MySQLi object. Supported since TBS version 3.7.0. | An SQL statement |
| MySQL | A MySql connection identifier or the keyword 'mysql' | An SQL statement |
| A MySql result identifier | - | |
| PostgreSQL | A PostgreSql connection identifier | An SQL statement |
| A PostgreSql result identifier | - | |
| SQLite | An SQLite connection identifier | An SQLite statement |
| An SQLite result identifier | - | |
| custom |
A keyword, an object or a resource identifier not mentioned in this table. See the chapter 'database plug-ins'. |
An SQL statement or something else. |
Php data sources:
Assigned
Text
Number
Clear
Conditional
Array
The argument Source has to be equal to 'assigned' or be omitted.
The block is merged with the arguments defined in the property Assigned.
Example : $TBS->MergeBlock('b1');
The block is merged with the arguments defined in the property Assigned.
Example : $TBS->MergeBlock('b1');
Versioning: the keyword 'assigned' is supported since TBS version 3.5.
Text
The argument Source has to be equal to 'text'.
The whole block is replaced by the text (it must be a string) given as the Query argument. No linked Fields are processed except '#' which returns 1, or 0 if Query is an empty string.
Example: $TBS->MergeBlock('b1','text','Hello, how are you?');
The whole block is replaced by the text (it must be a string) given as the Query argument. No linked Fields are processed except '#' which returns 1, or 0 if Query is an empty string.
Example: $TBS->MergeBlock('b1','text','Hello, how are you?');
Number
The argument Source has to be equal to 'num'.
The argument Query can be either a number or an array.
Examples:
The argument Query can be either a number or an array.
| arg Query | Returned Record Set |
| Number: | This number has to be positive or equal to zero. The returned Record Set consists of a column 'val' where the value goes from 1 to this number. |
| Array: | This array has to contain a key 'min' and a key 'max' and eventually a key 'step'. The returned Record Set consists of a column 'val' which goes from the 'min' value to the 'max' value. |
$TBS->MergeBlock('b1','num',12);
$TBS->MergeBlock('b2','num',array('min'=>20,'max'=>30));
$TBS->MergeBlock('b3','num',array('min'=>10,'max'=>20,'step'=>2));
$TBS->MergeBlock('b2','num',array('min'=>20,'max'=>30));
$TBS->MergeBlock('b3','num',array('min'=>10,'max'=>20,'step'=>2));
Clear
The argument Source has to be the keyword 'clear'.
All blocks and sections are deleted. It is the same thing as merging with an empty array.
Example: $TBS->MergeBlock('b1','clear');
All blocks and sections are deleted. It is the same thing as merging with an empty array.
Example: $TBS->MergeBlock('b1','clear');
Conditional
The argument Source has to be the keyword'cond'.
The block is merged like it was a conditional blocks onload and onshow. The block is not merged with data, and so it must have no linked TBS field. Each block section needs a parameter when or a parameter default. See conditional blocks for more details.
Example: $TBS->MergeBlock('bz','cond');
The block is merged like it was a conditional blocks onload and onshow. The block is not merged with data, and so it must have no linked TBS field. Each block section needs a parameter when or a parameter default. See conditional blocks for more details.
Example: $TBS->MergeBlock('bz','cond');
Array
The argument Source has to be a PHP Array or the keyword 'array'. If you use the keyword 'array', then the argument Query has to be a Php Array or a string that represents an array contained or nested in a global variable.
String syntax: 'globvar[item1][item2]...'
There are two advantages in using a string to represent the array:
-> Items will be read directly in the Array (assigned by reference) instead of reading a copy of the items. This can improve the performance.
-> You can use dynamic queries.
Displaying the key of current record:
You can use the virtual column '$' which will display the key of the current record. This can be useful especially for subblocks with dynamic queries.
Example: [block1.$]
Structure of supported arrays:
Items of the specified Array can be of two kinds: simple values with associated keys (case 1), or array values for whom items are themselves simple values with associated keys (case 2).
Case 1:
The returned Record Set consists of a column 'key' containing the name of the key, and a column 'val' containing the value of the key.
Case 2:
The returned Record Set consists of the columns 'column1', 'column2',... with their associated values.
String syntax: 'globvar[item1][item2]...'
'globvar' is the name of a global variable $globvar which must be an array.
'item1' and 'item2' are the keys of an item or a subitem of $globvar.
Example:
Example:
'item1' and 'item2' are the keys of an item or a subitem of $globvar.
Example:
$TBS->MergeBlock('block1','array','days[mon]');
This will merge 'block1' with the value $day['mon'] assuming it is an array.
It is possible to represent variable's name without items.This will merge 'block1' with the value $day['mon'] assuming it is an array.
Example:
$TBS->MergeBlock('block1','array','days');
There are two advantages in using a string to represent the array:
-> Items will be read directly in the Array (assigned by reference) instead of reading a copy of the items. This can improve the performance.
-> You can use dynamic queries.
Displaying the key of current record:
You can use the virtual column '$' which will display the key of the current record. This can be useful especially for subblocks with dynamic queries.
Example: [block1.$]
Structure of supported arrays:
Items of the specified Array can be of two kinds: simple values with associated keys (case 1), or array values for whom items are themselves simple values with associated keys (case 2).
Case 1:
| Example: | ['key1']=>value1 ['key2']=>value2 ... |
Case 2:
| Example: | [0] => (['column1']=>value1-0 ; ['column2']=>value2-0 ; ...) [1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...) [2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...) ... |
method Show():
Terminates the merge.
Syntax: $TBS->Show({int Render})
The Show() method performs the following actions:
- Merge [var] fields (for compatibility with version prior to 3.2.0),
- Merge [onshow] fields and blocks,
- Display the result (this action can be cancelled by Render property/argument),
- End the script (this action can be cancelled by Render property/argument).
The Render property/argument allows to adjust the behavior of the Show() method. See the Render property for more information.
Syntax: $TBS->Show({int Render})
The Show() method performs the following actions:
- Merge [var] fields (for compatibility with version prior to 3.2.0),
- Merge [onshow] fields and blocks,
- Display the result (this action can be cancelled by Render property/argument),
- End the script (this action can be cancelled by Render property/argument).
The Render property/argument allows to adjust the behavior of the Show() method. See the Render property for more information.
method GetBlockSource():
Returns the source of a TBS Block from the template.
If no block is found, the method returns False.
Syntax: string $TBS->GetBlockSource(string BlockName {, boolean AsArray}{, boolean DefTags}{, mix ReplaceWith})
This method enables you to get the source of a block in order to manually handle the merging.
After that, if you need to replace the block with text, you can use the MergeBlock() method with the 'text' parameter.
If no block is found, the method returns False.
Syntax: string $TBS->GetBlockSource(string BlockName {, boolean AsArray}{, boolean DefTags}{, mix ReplaceWith})
| Argument | Description |
| BlockName | The name of the block to search for. |
| AsArray | Optional. The default value is False. If this parameter is True the method returns the source of the block as a PHP array instead of a string. If the result is an array, then each sections of the block is saved as an item. First item is index 1. |
| DefTags | Optional. The default value is True. By default, the method GetBlockSource() returns the source of the block including its definition tags. If you'd like those tags to be deleted, then force the argument DefTags to False. If the block is defined with a simplified syntax then the definition tags will not be deleted anyway because they are also Field tags. Versioning: this argument is supported since TBS version 3.0. |
| ReplaceWith | Optional. Default value is False. If this argument is a string then
the block source is replaced with it in the template. You can use ReplaceWith = '' (empty string) in order to delete the block source from the template. Versioning: this argument is supported since TBS version 3.05. |
This method enables you to get the source of a block in order to manually handle the merging.
After that, if you need to replace the block with text, you can use the MergeBlock() method with the 'text' parameter.
Versioning: Since TBS 3.05 if AsArray is False then the method returns block with all its sections ; before TBS 3.05 it return only the first section. Since TBS 3.05 if AsArray is True and the block is not found then the method returns False ; before TBS 3.05 it return an empty Array.
method MergeField():
Replaces one or several TBS Fields with a fixed value or by calling a user function.
Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).
Each TBS fields having the specified base name will be merged.
It is also possible to merge the special [onload], [onshow] and [var] (see below).
Syntax: $TBS->MergeField(string BaseName, mixed X {, boolean FunctionMode}{, array DefaultPrm})
Merging with a value:
X can be numeric, string, an array or an object. For an array or an object, names of TBS Fields must have suffixes like automatic fields ([onload] and [onshow]).
Example:
Merging with a user function:
TBS calls this function for each field found in the template.
This function must have the following syntax:
Example:
Merge automatic fields and blocks:
You can use the method MergeField() in order to force the merge of the automatic fields and blocks ([onload] and [onshow]). But in this case, only the first argument should be indicated.
Example: $TBS->MergeField('var');
Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).
Each TBS fields having the specified base name will be merged.
It is also possible to merge the special [onload], [onshow] and [var] (see below).
Syntax: $TBS->MergeField(string BaseName, mixed X {, boolean FunctionMode}{, array DefaultPrm})
| Argument | Description |
| BaseName | Base name of the TBS Fields. For example 'account'. |
| X | The value to display (or a string that represent the name of a user function if the argument FunctionMode is set to true). |
| FunctionMode | Indicates that the value to display is calculated by a user function. The default value is false. If this argument is set to true, then X must be a text string giving the name of the user function. This function must exist and have the syntax described below. |
| DefaultPrm | List of parameters to apply by default to the merged fields. Parameters have to be given as an associative PHP array. If a parameter is defined in both argument DefaultPrm and in the field, then the parameter of the field will be taken in account. |
Merging with a value:
X can be numeric, string, an array or an object. For an array or an object, names of TBS Fields must have suffixes like automatic fields ([onload] and [onshow]).
Example:
$TBS->MergeField('account',array('id'=>55,'name'=>'Bob'));
In this example, the fields [account.id] and [account.name] will be merged.
Merging with a user function:
TBS calls this function for each field found in the template.
This function must have the following syntax:
function fct_user($Subname [, $PrmLst]) {...}
When the function is called, its argument $Subname has for value the suffix of the field's name (example: for a field named 'ml.title', $Subname will have the value 'title'). And the optional argument $PrmLst contains an associative array with the field's parameters. The function must return the value to be merged. Example:
$TBS->MergeField('ml','m_multilanguage',true);
...
function m_multilanguage($Subname) {
global $lang_id;
$rs = mysql_query("SELECT text_$lang_id AS txt FROM t_language WHERE key='$Subname");
$rec = mysql_fetch_array($rs);
return $rec['txt'] ;
}
...
function m_multilanguage($Subname) {
global $lang_id;
$rs = mysql_query("SELECT text_$lang_id AS txt FROM t_language WHERE key='$Subname");
$rec = mysql_fetch_array($rs);
return $rec['txt'] ;
}
In this example, a field such as [ml.title] will be merged with the value returned by m_multilanguage('title').
Merge automatic fields and blocks:
You can use the method MergeField() in order to force the merge of the automatic fields and blocks ([onload] and [onshow]). But in this case, only the first argument should be indicated.
Example: $TBS->MergeField('var');
Versioning: the merge of special fields is supported since TBS version 3.0. It replaces the old method MergeSpecial() which is not supported anymore.
Method PlugIn():
Enables you to call a TBS plug-in's command, or to install a TBS plug-in.
Syntax: mixed $TBS->PlugIn(mixed arg1, mixed arg2, ...)
Remind: in order to have your TBS plug-in working, its PHP script must be included in your application before.
Example: include_once('tbs_plugin_xxx.php');
And aslo, every TBS plug-in should have a key as explained at Plug-ins.
Calling a plug-in's command:
Use the plug-in's key as the main argument. Next arguments are for the called plug-in's purpose.
Example:
Remark: when you call a plug-in's command for the first time this plug-in is automatically installed on the TBS instance ($TBS).
Installing a plug-in:
Although some plug-ins are automatically installed, it can be useful in some other cases to make a manual installation. For this, use the constant TBS_INSTALL with the plug-in's key.
Example:
Remarks:
* A plug-in is installed relatively to a TBS instance (a variable $TBS for example). If you are using a second TBS instance (for example $TBS2) then you will also need to install the plug-in on this instance.
* A plug-in is installed automatically when you call one of its commands using the method PlugIn() (se above).
Syntax: mixed $TBS->PlugIn(mixed arg1, mixed arg2, ...)
Remind: in order to have your TBS plug-in working, its PHP script must be included in your application before.
Example: include_once('tbs_plugin_xxx.php');
And aslo, every TBS plug-in should have a key as explained at Plug-ins.
Calling a plug-in's command:
Use the plug-in's key as the main argument. Next arguments are for the called plug-in's purpose.
Example:
$TBS->PlugIn(TBS_XXX,$arg1,arg2);
In this example, the plug-in identified by the key TBS_XXX is called.Installing a plug-in:
Although some plug-ins are automatically installed, it can be useful in some other cases to make a manual installation. For this, use the constant TBS_INSTALL with the plug-in's key.
Example:
$TBS->PlugIn(TBS_INSTALL,TBS_XXX);
In this example, the plug-in identified by the key TBS_XXX is installed.* A plug-in is installed relatively to a TBS instance (a variable $TBS for example). If you are using a second TBS instance (for example $TBS2) then you will also need to install the plug-in on this instance.
* A plug-in is installed automatically when you call one of its commands using the method PlugIn() (se above).
Versioning: the method PlugIn() is supported since TBS version 3.0.
Property Assigned:
Enables you to define information for a subsequent merging which can be automatic or manual.
Syntax: array $TBS->Assigned
Property Assigned is a PHP array defined by the user. Arguments for methods MergeBlock() and MergeField() can be saved there. Arguments have to be saved in a PHP array with numerical keys and ordered following the syntax of those methods. It is possible to use optional string keys in order to define specific behaviors:
Example of a manual merging:
Example of an automatic merging:
Example of merging fields:
Notes:
- To merge an assigned block or field, you just have to call the corresponding method using only the name of the assigned key. You can add the argument Source = 'assigned', but this is optional because it is the default value. In other words, $TBS->MergeBlock('b') is equivalent to $TBS->MergeBlock('b', 'assigned').
- An assignment with 'auto'=>'onload' will be merged, of course, only if it is defined before calling the LoadTemplate() method.
- You can pass some arguments by reference for you assignments. This is particularly useful for PHP 4 which is passing object with a copy by default.
Syntax: array $TBS->Assigned
Property Assigned is a PHP array defined by the user. Arguments for methods MergeBlock() and MergeField() can be saved there. Arguments have to be saved in a PHP array with numerical keys and ordered following the syntax of those methods. It is possible to use optional string keys in order to define specific behaviors:
| Optional key | Description |
| 'type'=>'mergeblock' | Indicates that arguments are for the MergeBlock() method. This key is optional because it is the default behavior. |
| 'type'=>'mergefield' | Indicates that arguments are for the MergeField() method. |
| 'auto'=>'onload' | Indicates that the merging must be started automatically after [onload] tags. |
| 'auto'=>'onshow' | Indicates that the merging must be started automatically after [onshow] tags. |
| 'merged'=>0 | This key is added automatically by TBS during the merging. It counts the number of times this entry was merged. |
Example of a manual merging:
$TBS->Assigned['b'] = array('b1,b2', &$cnt_id, 'SELECT id, name FROM table1');
...
$TBS->MergeBlock('b'); // merge block b1 and b2 with the SQL query
...
$TBS->MergeBlock('b'); // merge block b1 and b2 with the SQL query
$TBS->Assigned['b'] = array('b1,b2', &$cnt_id, 'SELECT id, name FROM table1', 'auto'=>'onload');
Example of merging fields:
$TBS->Assigned['f1'] = array('f1', $data, 'type'=>'mergefield');
...
$TBS->MergeField('f1'); // merge field f1 witht the array $data
...
$TBS->MergeField('f1'); // merge field f1 witht the array $data
Notes:
- To merge an assigned block or field, you just have to call the corresponding method using only the name of the assigned key. You can add the argument Source = 'assigned', but this is optional because it is the default value. In other words, $TBS->MergeBlock('b') is equivalent to $TBS->MergeBlock('b', 'assigned').
- An assignment with 'auto'=>'onload' will be merged, of course, only if it is defined before calling the LoadTemplate() method.
- You can pass some arguments by reference for you assignments. This is particularly useful for PHP 4 which is passing object with a copy by default.
Versioning: property Assigned is supported since TBS version 3.5.
property NoErr:
Enables you to avoid all TinyButStrong error messages for next operations. Default value is false. The errors that were not displayed can however be returned with the special field [onshow..error_msg]. Furthermore you can check the presence of error using property ErrCount which counts TBS errors regardless of Noerr.
Syntax: boolean $TBS->NoErr
Property NoErr is useful in two cases:
- For professional sites put into production for whom no error message can be displayed. Take care because you will have no more indication about the good running of the merge. It is often more judicious to use parameter noerr which enables you to avoid messages concerning one particular TBS tag.
- For merges that do not accept TinyButStrong basic error messages. For example, an OpenOffice document will not open correctly if a TBS error occurs. Use $TBS->NoErr=true and the field [onshow..error_msg] to display TBS errors in a viewable place of your OpenOffice document.
Syntax: boolean $TBS->NoErr
Example: $TBS->NoErr = true; // no more error message is displayed
Property NoErr is useful in two cases:
- For professional sites put into production for whom no error message can be displayed. Take care because you will have no more indication about the good running of the merge. It is often more judicious to use parameter noerr which enables you to avoid messages concerning one particular TBS tag.
- For merges that do not accept TinyButStrong basic error messages. For example, an OpenOffice document will not open correctly if a TBS error occurs. Use $TBS->NoErr=true and the field [onshow..error_msg] to display TBS errors in a viewable place of your OpenOffice document.
Versioning:
- Property NoErr is supported since TBS version 3.0.
- Special field [onshow..error_msg] is supported since TBS version 3.5.0.
- Property NoErr is supported since TBS version 3.0.
- Special field [onshow..error_msg] is supported since TBS version 3.5.0.
property Render:
Indicates how the merging ends.
The value must be a combination of the following constants.
The default value is (TBS_OUTPUT + TBS_EXIT).
Syntax: int $TBS->Render
The Render property changes the behavior of the Show() method.
The value must be a combination of the following constants.
The default value is (TBS_OUTPUT + TBS_EXIT).
Syntax: int $TBS->Render
The Render property changes the behavior of the Show() method.
| Constant | Description |
| TBS_NOTHING | Indicates that none of the actions below are processed at the end of the merge. |
| TBS_OUTPUT | Indicates that the result of the merge must be displayed. TBS uses the Php command Echo. |
| TBS_EXIT | Indicates that we have to quit the script just after the end of the merge. |
property Source:
This property contains the source of the template currently merged. It is read/write.
When TinyButStrong processes a merging (when using the MergeBlock() method for example), the Source property is modified immediately.
Syntax: string $TBS->Source
Notes:
- The LoadTemplate() method loads a file into the Source property and merges the [onload] tags automatically. Thus, Source may be different from the original template after LoadTemplate().
- The Show() method merges [onshow] tags automatically before to display the result.
In order to load a template stored into a Php variable, you can code:
In order to store the result at the end of the merging, you can code:
When TinyButStrong processes a merging (when using the MergeBlock() method for example), the Source property is modified immediately.
Syntax: string $TBS->Source
Notes:
- The LoadTemplate() method loads a file into the Source property and merges the [onload] tags automatically. Thus, Source may be different from the original template after LoadTemplate().
- The Show() method merges [onshow] tags automatically before to display the result.
In order to load a template stored into a Php variable, you can code:
$TBS->Source = $my_template;
$TBS->LoadTemplate(null); // run plug-ins if any, and merges [onload] tags if any
$TBS->LoadTemplate(null); // run plug-ins if any, and merges [onload] tags if any
In order to store the result at the end of the merging, you can code:
$TBS->Show(TBS_NOTHING); // terminate the merging without leaving the script nor to display the result
$result = $TBS->Source;
$result = $TBS->Source;
property TplVars:
Contains the array of template variables corresponding to current template.
Syntax: array $TBS->TplVars
You can define template variables using one or several onload automatic fields with parameter tplvars. All parameters that follow parameter tplvars are added to the TplVars property when the LoadTemplate() method is called.
- Parameter tplvars works only with onload automatic fields.
- You can use parameter tplvars several times in the same template.
Syntax: array $TBS->TplVars
You can define template variables using one or several onload automatic fields with parameter tplvars. All parameters that follow parameter tplvars are added to the TplVars property when the LoadTemplate() method is called.
Example:
[onload;tplvars;template_version='1.12.27';template_date='2004-10-26']
This TBS tag will create two items equivalent to the PHP code:
$TBS->TplVars['template_version'] = '1.12.27';
$TBS->TplVars['template_date'] = '2004-10-26';
Remarks:[onload;tplvars;template_version='1.12.27';template_date='2004-10-26']
This TBS tag will create two items equivalent to the PHP code:
$TBS->TplVars['template_version'] = '1.12.27';
$TBS->TplVars['template_date'] = '2004-10-26';
- Parameter tplvars works only with onload automatic fields.
- You can use parameter tplvars several times in the same template.
Object Oriented Programming (OOP):
TinyButStrong integrate a technique to call methods or properties of objects that you've coded at the PHP side.
Calling methods of a class without created object:
Calling created objects:
Calling methods of a class without created object:
The following TBS features support the call to the methods of a class without created object.
Remark: Methods call using this technique must respect the function syntax expected by the feature (see the description of the corresponding feature).
| Feature | Example |
| Parameter ondata | [blk1.column1;block=tr;ondata=MyClass.methA] |
| Parameter onformat | [blk1.column2;onformat=MyClass.methB] |
| Method LoadTemplate() | $TBS->LoadTemplate('mytemplate.htm','=MyClass.methC'); |
| Method MergeField() | $TBS->MergeField('myfield','MyClass.methD',true); |
Calling created objects:
TBS has an ObjectRef property that is set to false by default, and that you can use to reference your objects already created. You can reference an object directly on the ObjectRef property, or you can reference some using PHP arrays.
Example:
* Think to use the assignment by reference using "=&" instead of "=", otherwise a copy of the object will be created.
* Since an object is referenced under ObjectRef, its sub objects will also be accessible by the TBS syntax.
• Using ObjectRef in automatic fields:
Use the symbol '~' to call what is referenced under ObjectRef.
For example (valid for both [onload], [onshow] and [var]):
Remark:
TBS proceeds to a coherence control, it will determine itself whether your automatic field definition is calling to ObjectRef via an array's item, an object's property or an object's method. Anyway, take care that your automatic field must call a value at the end, not an object.
• Using ObjectRef in other TBS features:
The following TBS features support the call to the methods of objects referenced under ObjectRef.
Remark: Methods call using this technique must respect the function syntax expected by the feature (see the description of the corresponding feature).
Example:
$TBS->ObjectRef =& $MyObject1;
You can use an array if you have several objects reference:
$TBS->ObjectRef['item1'] =& $MyObject1;
$TBS->ObjectRef['item2'] =& $MyObject2;
You can use as many levels as you wish:
$TBS->ObjectRef['item3']['a'][0] =& $MyObject4;
Remarks:You can use an array if you have several objects reference:
$TBS->ObjectRef['item1'] =& $MyObject1;
$TBS->ObjectRef['item2'] =& $MyObject2;
You can use as many levels as you wish:
$TBS->ObjectRef['item3']['a'][0] =& $MyObject4;
* Think to use the assignment by reference using "=&" instead of "=", otherwise a copy of the object will be created.
* Since an object is referenced under ObjectRef, its sub objects will also be accessible by the TBS syntax.
• Using ObjectRef in automatic fields:
Use the symbol '~' to call what is referenced under ObjectRef.
For example (valid for both [onload], [onshow] and [var]):
| The field | Will call | |
| [onshow.~propA] | $TBS->ObjectRef->propA | |
| [onshow.~propA.propB] | $TBS->ObjectRef->propA->propB | |
| [onshow.~item2.propA] | $TBS->ObjectRef['item2']->propA | |
| [onshow.~item2.methX] | $TBS->ObjectRef['item2']->methX() | |
| [onshow.~item2.methY(a,b)] | $TBS->ObjectRef['item2']->methY('a','b') |
TBS proceeds to a coherence control, it will determine itself whether your automatic field definition is calling to ObjectRef via an array's item, an object's property or an object's method. Anyway, take care that your automatic field must call a value at the end, not an object.
• Using ObjectRef in other TBS features:
The following TBS features support the call to the methods of objects referenced under ObjectRef.
| Feature | Example |
| Parameter ondata | [blk1.column1;block=tr;ondata=~item1.methA] |
| Parameter onformat | [blk1.column2;onformat=~item1.methB] |
| Method LoadTemplate() | $TBS->LoadTemplate('mytemplate.htm','=~item1.methC'); |
| Method MergeField() | $TBS->MergeField('myfield','~item1.methD',true); |
| Method MergeBlock() | $TBS->MergeBlock('blk1','~mydb','SELECT * FROM t_table'); |
Template side:
You design your template by placing TBS tags in the places where data items should appear.There are two types of TBS tags: Fields and Blocks.
A TBS Field is a TBS tag which has to be replaced by a single data item. It is possible to specify a display format and also other parameters. The syntax for TBS Fields is described below.
A TBS Block is an area which has to be repeated. It is defined using one or two TBS fields.
Most often, it is the row of an HTML table. The syntax for TBS Blocks is described below.
TBS Fields:
A TBS field is a TBS tag which has to be replaced by a single data item.
A TBS fields must have a name to identify it (which does not have to be unique) and can have parameters to modify the displayed value.
Syntax: TEMPLATE ... [FieldName{;param1}{;param2}{;param3}{...}] ... TEMPLATE
When you whant to use several paremeters in the same TBS field, then it can be intersing to undertsand in which order they are processed.
Each parameter is changing the value to be merged, but the source from where the value is is taken is not changed.
Order:
1) -> Retreiving the value of the field to be merged.
2) -> Changing the value using parameters:
2.1) -> onformat
2.2) -> ope / plug-ins OnOperation
2.3) -> frm / XML/HTML or other char conversion
2.4) -> if
2.5) -> file
2.6) -> script
2.7) -> att
2.8) -> . / ifempty / magnet
3) -> Inserting the value in the template.
A TBS fields must have a name to identify it (which does not have to be unique) and can have parameters to modify the displayed value.
Syntax: TEMPLATE ... [FieldName{;param1}{;param2}{;param3}{...}] ... TEMPLATE
| Element | Description |
| FieldName | The name of the Field. Warning: names that begin with onload, onshow and var.are reserved for automatic fields. |
| param1 | Optional. One or more parameters from the list below and separated with ';'. Some parameters can be set to a value using the equal sign '='. Example: frm=0.00 If the value contains spaces, semicolons or quotes, then you can use single quotes as delimiters. Example: frm='0 000.00' To specify a literal single quote, escape it with a second single quotes. Example: ifempty='hello that''s me' A parameter can contain embedded TBS fields, but only under special circumstances: - the embedded field is merged before the parent field, - the embedded field if a [var] field placed into a parameter file, script, if, then, else or when. In the other cases; the embedded TBS field will not be processed and will be taken as is, like text. Examples: [x;htmlconv=[var.y]] : [var.y] will not be merged and parameter "htmlconv" will have an unvalid value. [x;if [var.y]=1] : [var.y] will be correctly merged and the "if" condition will be correctly evaluated. |
Field's parameters:
| Parameter | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| htmlconv=val | Ennables you to modify the special character conversion for this TBS field only. Note that the special character conversion used by default for all TBS fields is the one defined by LoadTemplate(). It is often corresponding to an Xml/Html charset but not necessary. The value val can be one of the following keywords:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| . (dot) | If the data item is empty, then an unbreakable space is displayed. Useful for cells in tables. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ifempty=val | If the data item is empty, then it is replaced with the specified value. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| att=path | Move the current field into an attribute of an XML/HTML tag before it is merged. This parameter is very useful when it is too difficult for the template designer to place a TBS field into an attribute. The value path must indicate the place of the attribute relatively to the current field. If the attribute doesn't exist in the specified tag, then it is created. If the attribute already exists in the specified tag and it has already a value, then the field replaces all the current value. You can chose to place the field as an added value using parameter attadd. You can complete the attribute's value by applying a mask to it using parameter ope=msk. You can delete the attribute in case of empty value using parameter magnet=#. Syntax for value path: [+][tag1+tag2+tag3+...#]attribute By default the attribute is searched before the current field. But if '+' is the first character of the path, then it is searched after. If no tag list is specified, then the attribute is looked at in the first tag met in the search direction. If a tag list is used, tag1 is search first, then tag2, ... regardless of the direction of the search (before/after). You can put a tag name between one or several bracket levels in order to specify that the searched tag must embed the current field. Examples: [onshow.x;att=class] moves into attribute 'class' of the first tag placed before.
[onshow.x;att=div#class] moves into attribute 'class' of the first
 placed before. [onshow.x;att=+div#class] moves into attribute 'class' of the first
 placed after. [onshow.x;att=((div))#class] moves into attribute 'class' of the second embedding
 placed before. [onshow.x;att=table+div#class] moves into attribute 'class' of the first
 after the first
 placed before. Notes: - Method MergeBlock() cannot move a TBS field over another TBS field placed after it. This makes a TBS error to occur. - When the attribute has no value before the field is moved, then TBS chooses what string delimiter to use regarding other attributes (XML/HTML accepts both (") and (')). You can force the delimiter you need using property $TBS->AttDelim. Versioning: Parameter att is supported since TBS version 3.5.0 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| attadd | To be used with parameter att. Indicate that the field is added into the attribute's value, instead of being replacing the attribute's value. Please note that the added value won't be simply concatenated with previous values, it will be added with a space character separator in order to perform an adding to the meaning of attributes. Example:
[onshow.x;att=class;attadd]
There is no way for now to simply concatenate the field's value with the previous attribute's value. But instead, you can use parameter ope=msk in order to apply a mask to the field's value.in this example, if we have $x='style2' then we obtain
 Example:
[onshow.z;att=class;ope=msk:style*]
in this example, if we have $z='2' then we obtain
 Versioning: Parameter attadd is supported since TBS version 3.5.0 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| atttrue or atttrue=value |
To be used with parameter att. Indicates that the attribute (indicated with parameter att) must be managed as a boolan XHTML/HTML attribute. I.e. it is either present in the tag with the format attribute="attribute" in order to mean TRUE, or ommited in the tag in order to mean FALSE. If atttrue is set with a given value, then the boolean attribute will be TRUE (present) if the field is equal to this value, otherwise it will be FALSE (omitted). If atttrue is set with no value, then the boolean attribute will be TRUE (present) if the field's value is non empty, and it will be FALSE (omitted) if the field's value is empty. Examples: <input type="checkbox">[onshow.accept;att=selected;atttrue=1]
Versioning: Parameter atttrue is supported since TBS version 3.6.0 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| magnet=tag or magnet=expr |
Assign a magnet XML/HTML zone to the TBS field. A magnet tag is kept as is when the field has a value, and is deleted when the field is null or empty string. Parameter magnet supports the same syntax as parameter block, i.e. that expr must be an XML/HTML tag or a TBS extended block expression. Example:
By default, the magnet XML/HTML zone should be delimited by a pair of opening-closing tags (like ) which first tag is placed before the TBS fields. But this can be changed using parameter mtype (see below).(click here) Result for $link='www.tbs.com': (click here) Result for $link='': () Since TBS version 3.3.0, parameter ope has keywords (nif, minv, mok and mko) that improve parameter magnet. Remark: the parameters if then else are processed before parameter magnet. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mtype=val | To be used with parameter magnet. Define the magnet type.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comm | Widen the bounds of the TBS Field up to the bounds of the commentary Html tags which surround it, or up to another specified couple of XML/HTML tags. Example: xxx  yyy
orxxx
 [myfield;comm=div] here some comments
 yyy
are strictly identical to:xxx [myfield] yyy
This parameter is particularly useful for the template designing when you are using a Visual HTML Editor (such as Dreamweaver or FrontPage).Versioning: Support for other XML/HTML tags was added in TBS 3.0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| noerr | Avoid some of the TBS Error messages. When a message can be cancelled, it is mentioned in the message. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file=filename | Replace the field with the contents of the file. Filename can be a string or an expression. You can use the keyword [val] inside the expression to insert the current data item. You can use [var] fields inside the expression. If parameter script is used by omitting the filename value (example: [onshow.file;script;subtpl]), then the field's value is used for the file name. If the file is not found, then it will be searched in the folder of the last loaded template (since TBS version 3.2.0). Examples: [onload;file=header.html]
If filename is an empty string, then no error message is displayed, it is like parameter file is ignored. This can be used to manage conditional insertion. [onload;file=[var.filename]] Example: [onload;file=[var.insert;if [val]=1;then 'header.html';else '']]
You will found more details about this parameter in the chapter Subtemplates.See also: getbody script |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getbody=taglist | To be used with parameter file or script. Indicates that not all the file contents is loaded but only some XML/HTML parts of it defined with the tag list. The tags of the list must be separated with plus (+), and placed between parentheses if you want the tags themselves to be retrieved with their content. If the file has several XML/HTML part of a tag, all those parts will be automatically concatenated. If parameter getbody is used without value, then the  tag is taken by default. Example: [onload;file=header.htm;getbody=(script)+(style)+body]
Versioning: parameter getbody is supported since TBS version 3.0.
In previous versions, it was automatically processed when using parameter file. Now it becomes explicit. The tag list is supported since TBS version 3.5.0. Before this version, the value of getbody can be only one tag without parentheses. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rename old=new | To be used with parameter file or script. Renames TBS blocks and fields in the subtemplate before it is inserted. You can define several block to rename by separate them with coma. If a new name is an empty string then the old block is deleted by merging it with an empty array. This parameter is useful when you want to use the same subtemplate several times in the main template. Example: Address 1: [onload;file=address.htm]
Address 2: [onload;file=address.htm;rename town1=town2,zip1=zip2,email=] Versioning: parameter rename is supported since TBS version 3.5.1.
See chapter 'Subtemplates' for more details about subtemplates. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| script=filename | Execute the Php script just before replacing the TBS field. Filename can be a string or an expression. You can use the keyword [val] inside the expression to insert the current data item. You can use [var] fields inside the expression. If parameter script is used by omitting the filename value (example: [onshow.file;script;subtpl]), then the field's value is used for the file name. If the file is not found, then it will be searched in the folder of the last loaded template (since TBS version 3.2.0).
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subtpl | To be used with the parameter script or parameter onformat. Activate the subtemplate mode during the script or function execution. See chapter 'Subtemplates' for more details. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if expr1=expr2 | Display the data item only if the condition is verified, otherwise display nothing unless parameter then or else are used. Supported operators are:
You can use the keyword [val] inside the expression to insert the current data item. You can use [var] fields inside the expression. The expressions may contain other TBS fields, but you have to make sure that they are merged before the containing field. Since TBS version 3.0, it is also possible to define several couples of if/then in the same field. See parameters then and else for some examples. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| then val1 | If the parameter if is defined and its condition is verified, then the data item is replaced with val1. Since TBS version 3.0, it is also possible to define several couples of if/then in the same field. Examples: [onshow.image;if [val]='';then 'image0.gif']
You can use the keyword [val] inside the expression to insert the current data item.[onshow.x;if [val]=1;then 'one';if [val]=2;then 'two';else 'more'] You can use [var] fields inside the expression. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else val2 | If the parameter if is defined and its condition is not verified, then the data item is replaced with val2. Example: [onshow.error_id;if [val]=0;then 'no error';else 'error found']
You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onformat=fct_name | Indicates the name of a user Php function that will be executed at the time when the value is formated for the merge. This allows typically to modify the text to display. Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP). The function fct_name must have the following syntax: function fct_name($FieldName,&$CurrVal,{&$CurrPrm,{&$TBS}}) { ... }
Since TBS version 3.6.0, it's possible to limit the allowed PHP functions for parameter onformat. See create a new TBS object. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protect=val | Enables you to protect or unprotect the data item to be merged by replacing the characters '[' with their corresponding XML/HTML code '['. The value val can be one of the following keywords: yes: (default value) data item is protected. no: data item is not protected. By default, all data merged with a template is protected except if it's a file inclusion. It is strongly recommended to protect data when it comes from free enter like on a forum for example. Nevertheless, it is possible to disable the protection by default if you set property $TBS->Protect to false. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ope=action | Makes one or several operations on the value to merge. You can define several operations to be processed in order by separating them with coma (,). Example: [onshow.x;ope=add:-1,mod:10]
Supported operations are:
Versioning: - Parameter ope is supported since TBS version 3.0. It replaces parameter max which doesn't exist since this version. - Multiple operations and 'mul" and "div" are supported since TBS version 3.2.0 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| frm=format | Specify a format to display for a data item which type is date/time or numeric. It is possible to use a conditional format which changes depending on the sign of the value. The format is considered as numeric type as soon as it contains the character 0, otherwise it is considered as date/time type. Date-time format:
It is a VisualBasic like format. The following keywords are recognized:
Other characters are kept. It is possible to protect the strings inside by putting them between double quotes ("). Examples: [fld;frm=mm/dd/yyyy] will display 12/21/2002
[fld;frm='yyyy-mm-dd hh:nn:ss'] will display 2002-12-21 15:45:03 Versioning:
- Keywords ampm and AMPM are supported since TBS version 3.0. - Keyword hm was supported since TBS 3.0 and is deprecated an replaced with keyword rr since TBS version 3.2.0. - Keywords rr, r, and h are supported since TBS version 3.2.0. - Keyword (locale) is supported since TBS version 3.4.0. Numeric format:
To define the decimal part, use an expression like '0d0...' where 'd' is the decimal separator , and '0...' is a continuation of zeros corresponding to the number of decimals. If there is no decimal, use the format '0.' (with a dot). To define a thousand separator, use an expression like '0t000d...' where 't' is the thousand separator. If there is no decimal, use the format '0t000.' (with a dot). In order to display leading zeros, use an expression like '0000d...' where '0000' represents the number of digits you want to have. If there is no decimal, use the format '0000.' (with a dot). Versioning: This feature is supported since TBS version 3.5.2. If the format contains the character '%', then the value to display will be multiplied by 100. The character '%' is displayed too. The numerical format may contain other strings. But only the expression with one or more zeroes placed to the right will be taken as a format, other characters will be kept. Examples:
Conditional formats:
You have the possibility to define up to 4 conditional formats when the value is respectively positive, negative, zero or null (or empty string). Conditional formats must be separated by a '|' character. Each conditional format is optional. Examples:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| locale | Deprecated since TBS version 3.4.0. It does the same as the keyword (locale) used in parameter frm. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tplfrms | Enables you to define formats in the template that you can reuse for parameter frm. Works only with onload automatic fields. Example: [onload;tplfrms;doll=$ 0,000.00;mydt=yyyy-mm-dd] [onshow.amount;frm=doll] ... [onshow.date;frm=mydt] |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tplvars | Enables you to define variables in the template that you can retrieve in the Php programm using TplVars property. Works only with onload automatic fields. |
Order of processing parameters:
When you whant to use several paremeters in the same TBS field, then it can be intersing to undertsand in which order they are processed.
Each parameter is changing the value to be merged, but the source from where the value is is taken is not changed.
Order:
1) -> Retreiving the value of the field to be merged.
2) -> Changing the value using parameters:
2.1) -> onformat
2.2) -> ope / plug-ins OnOperation
2.3) -> frm / XML/HTML or other char conversion
2.4) -> if
2.5) -> file
2.6) -> script
2.7) -> att
2.8) -> . / ifempty / magnet
3) -> Inserting the value in the template.
Automatic fields
Automatic fields enable you to automatically merge PHP global variables when some events occur.
For example [onload.x] will be merged with the global variable $x when the LoadTemplate() method is called.
Automatic fields can only merge PHP variables when they are global. There is no way to merge a variable which is local to a function, unless you make a reference to it with a global variable, or if you merge it using MergeField().
Automatic fields can also merge TBS special information (see Special automatic fields), or data of the ObjectRef property (see Objet Oriented Programming).
There are three types of automatic fields:
- [onload] fields, which are automatically merged when the LoadTemplate() method is called.
- [onshow] fields, which are automatically merged when the Show() method is called.
- [var] fields, which are automatically merged when the field they are embedded in is also merged itself, but it works only if they are placed into a parameter file, script, if, then, else or when.
Automatic fields may or may not have a sub name, like x in [onload.x], [onshow.x] or [var.x]. An automatic field without sub name will be merged with an empty string value (''). Example: [onload;file=header.html] this field inserts a subtemplate when LoadTemplate() method is called.
An automatic field having a sub name will be merged with the corresponding global PHP variable.
If the global variable doesn't exist at this moment, then a TBS error is displayed, unless you add parameter noerr.
Examples:
You can also merge array's items, object's properties or object's methods using a dot (".") as separator. Resource variables are ignored.
For example (valid for both [onload], [onshow] and [var]):
Versioning: calling methods with arguments from an automatic field is supported since TBS version 3.0.
Note: You can also force the merge of [var] fields or other types at anytime using the MergeField() method.
Embedded automatic fields
An embedded TBS field is never merged, unless :
- it is merged before the parent field,
- il is a [var] field placed into a paremeter file, script, if, then, else or when.
Examples:
Security: how to limit automatic fields usage in templates?
You can limit the automatic fields usage by defining a prefix for allowed PHP variables. For details, see create a new TBS object.
Prevent from processing automatic fields [onload] and [onshow]
Properties $TBS->OnLoad and $TBS->OnShow enable you to cancel the processing of [onload] and [onshow] fields. Those properties accept only true of false values. This can be very useful especially, but not only, for some TBS plug-ins. Note that [var] fields are automatically processed even if $TBS->OnShow = false.
Example:
$TBS->OnShow = false;
Properties OnLoad and OnShow are supported since TBS version 3.6.0.
For example [onload.x] will be merged with the global variable $x when the LoadTemplate() method is called.
Automatic fields can only merge PHP variables when they are global. There is no way to merge a variable which is local to a function, unless you make a reference to it with a global variable, or if you merge it using MergeField().
Automatic fields can also merge TBS special information (see Special automatic fields), or data of the ObjectRef property (see Objet Oriented Programming).
There are three types of automatic fields:
- [onload] fields, which are automatically merged when the LoadTemplate() method is called.
- [onshow] fields, which are automatically merged when the Show() method is called.
- [var] fields, which are automatically merged when the field they are embedded in is also merged itself, but it works only if they are placed into a parameter file, script, if, then, else or when.
Versioning:
- Automatic fields [onload] and [onshow] are supported since TBS version 3.2.0. For compatibility with versions prior to 3.2.0, remaining [var] fields are still merged as if there were [onshow] fields but is it recommended to use real [onshow] fields instead.
- [var] are processed into parameter then and else since TBS version 2.02.
- Automatic fields [onload] and [onshow] are supported since TBS version 3.2.0. For compatibility with versions prior to 3.2.0, remaining [var] fields are still merged as if there were [onshow] fields but is it recommended to use real [onshow] fields instead.
- [var] are processed into parameter then and else since TBS version 2.02.
Automatic fields may or may not have a sub name, like x in [onload.x], [onshow.x] or [var.x]. An automatic field without sub name will be merged with an empty string value (''). Example: [onload;file=header.html] this field inserts a subtemplate when LoadTemplate() method is called.
An automatic field having a sub name will be merged with the corresponding global PHP variable.
If the global variable doesn't exist at this moment, then a TBS error is displayed, unless you add parameter noerr.
Examples:
[onload.x] this field will be merged with the global variable $x when LoadTemplate() is called.
[onshow.x] this field will be merged with the global variable $x when Show() is called.
[b1.col1;if [val]=[var.x];then 'good'; else 'bad'] : the [var.x] field is merged in the same time as [b1.col1].
[onshow.x] this field will be merged with the global variable $x when Show() is called.
[b1.col1;if [val]=[var.x];then 'good'; else 'bad'] : the [var.x] field is merged in the same time as [b1.col1].
You can also merge array's items, object's properties or object's methods using a dot (".") as separator. Resource variables are ignored.
For example (valid for both [onload], [onshow] and [var]):
| [onshow.tbl.item1] | will display | $tbl['item1'] | ||
| [onshow.tbl.item2.a.0] | will display | $tbl['item2']['a'][0] | ||
| [onshow.obj.prop1] | will display | $obj->prop1 | ||
| [onshow.obj.methA] | will display | $obj->methA() | ||
| [onshow.obj.methB(x,y)] | will display | $obj->methB('x','y') | ||
| [onshow.tbl.item3.prop2.item4 | will display | $tbl['item3']->prop2['item4'] |
Note: You can also force the merge of [var] fields or other types at anytime using the MergeField() method.
Embedded automatic fields
An embedded TBS field is never merged, unless :
- it is merged before the parent field,
- il is a [var] field placed into a paremeter file, script, if, then, else or when.
Examples:
[onload;if [onload.x]=1;then 'yes';else 'no']
This example will always display 'no', because the embedded [onload.x] fild will never be evaluated. It is better to use [onload;if [var.x]=1;then 'yes';else 'no'] instead, or better : [onload.x;if [val]=1;then 'yes';else 'no']
[b1.nom;block=tr;headergrp=[var.x]]
In this example, [var.x] will not be merged yet when you call $TBS->MergeBlock('b1',...)
The header will then be defined badly.
It needs one of those:
- using an onload field: [b1.name;block=tr;headergrp=[onload.x]]
- calling $TBS->MergeField('var') avant $TBS->MergeBlock('b1',...)
- using a customized field name: [b1.name;block=tr;headergrp=[zzz]] manually merged with $TBS->MergeField('zzz',$x)
This example will always display 'no', because the embedded [onload.x] fild will never be evaluated. It is better to use [onload;if [var.x]=1;then 'yes';else 'no'] instead, or better : [onload.x;if [val]=1;then 'yes';else 'no']
[b1.nom;block=tr;headergrp=[var.x]]
In this example, [var.x] will not be merged yet when you call $TBS->MergeBlock('b1',...)
The header will then be defined badly.
It needs one of those:
- using an onload field: [b1.name;block=tr;headergrp=[onload.x]]
- calling $TBS->MergeField('var') avant $TBS->MergeBlock('b1',...)
- using a customized field name: [b1.name;block=tr;headergrp=[zzz]] manually merged with $TBS->MergeField('zzz',$x)
Security: how to limit automatic fields usage in templates?
You can limit the automatic fields usage by defining a prefix for allowed PHP variables. For details, see create a new TBS object.
Prevent from processing automatic fields [onload] and [onshow]
Properties $TBS->OnLoad and $TBS->OnShow enable you to cancel the processing of [onload] and [onshow] fields. Those properties accept only true of false values. This can be very useful especially, but not only, for some TBS plug-ins. Note that [var] fields are automatically processed even if $TBS->OnShow = false.
Example:
$TBS->OnShow = false;
Properties OnLoad and OnShow are supported since TBS version 3.6.0.
Special automatic fields :
A Special [var] field is a TBS Field which displays data provided by the TinyButStrong system.
The name of a Special [var] field has to begin with 'var..', followed by a keyword in the list below.
The parameters for standard TBS Fields are available for Special [var] fields.
Example: Date of the day : [onshow..now;frm='mm-dd-yyyy']
(valid for both onload, onshow et var)
The name of a Special [var] field has to begin with 'var..', followed by a keyword in the list below.
The parameters for standard TBS Fields are available for Special [var] fields.
Example: Date of the day : [onshow..now;frm='mm-dd-yyyy']
(valid for both onload, onshow et var)
| Name | Description |
| onshow..now | Date and hour of the server. |
| onshow..version | The version of TinyButStrong. |
| onshow..script_name | The name of the PHP file currently executing. |
| onshow..template_name | The name of the last loaded template file. It is the name given to the LoadTemplate() method. |
| onshow..template_date | The creation date of the last loaded template file. |
| onshow..template_path | The directory of the last loaded template file. It is the directory given to the LoadTemplate() method. |
| onshow..tplvars.* | The value of an item set in the TplVars property. ('*' must be the key of an existing item in the array) |
| onshow..cst.* | The value of a PHP constant. (* must be the name of an existing constant) |
| onshow..tbs_info | Information about TBS and installed plug-ins. |
| onshow..error_msg | Display errors that have been avoid during the time when property NoErr is set to true. |
Versioning:
- special var fields "cst" and "tbs_info" are supported since TBS version 3.2.0.
- "error_msg" is supported since TBS version 3.5.0.
- special var fields "cst" and "tbs_info" are supported since TBS version 3.2.0.
- "error_msg" is supported since TBS version 3.5.0.
TBS Blocks:
A TBS block enables you define a zone and to display data from a record source.
You can define a TBS block using one or two TBS tags (see below).
Merging with data:
Merging a block with data is done using the MergeBlock() method. When a TBS block is merged with data, it is repeated as many times as there are records; and the associated TBS fields are replaced by the value of the columns stored in the current record.
A TBS field associated to a block is identified by its name which should be made of the name of the block followed by the name of the column to display and separated by a dot.
Examples:
Since TBS version 3.5.0 column names with spaces are accepted.
Remark: when two separated blocks have the same name, then they will be considered has two sections of the same block. All content placed between those two sections of a block will be ignored and deleted during the merging. See sections of blocks to know more about sections.
There are three possible syntaxes to define a TBS block:
The 'absolute' syntax is rarely used with Visual Editors because TBS tags have often to be placed between two XML/HTML tags. On the other hand, it is convenient for textual editors.
The 'relative' syntax enables you to indicate a block using only one TBS tag. Furthermore, there is no need to hide the TBS tag because it will be deleted during the displaying. This syntax is quite practical.
The 'simplified' syntax is really simple. It enables you to define a TBS block and a TBS Field with only one TBS tag. This syntax is the most current and the most practical.
Example:
<custom_tag>Hello [blk1.column1;block=custom_tag], how are you?</custom_tag>
You can define a TBS block using one or two TBS tags (see below).
Merging with data:
Merging a block with data is done using the MergeBlock() method. When a TBS block is merged with data, it is repeated as many times as there are records; and the associated TBS fields are replaced by the value of the columns stored in the current record.
A TBS field associated to a block is identified by its name which should be made of the name of the block followed by the name of the column to display and separated by a dot.
Examples:
- [Block1.ColA] This field will display the value of column ColA when block Block1 is merged.
- [Blokc1.ColB;frm='dd-mm-yyyy'] Another field but with a TBS parameter.
- [Blokc1.ColB;frm='dd-mm-yyyy'] Another field but with a TBS parameter.
Since TBS version 3.5.0 column names with spaces are accepted.
Remark: when two separated blocks have the same name, then they will be considered has two sections of the same block. All content placed between those two sections of a block will be ignored and deleted during the merging. See sections of blocks to know more about sections.
Block syntaxes:
There are three possible syntaxes to define a TBS block:
Explicit Syntax:
Two TBS tags are used. One for the beginning of the block and another for the end of the block.
Example:
TEMPLATE...[BlockName;block=begin;params]...TEMPLATE...[BlockName;block=end]...TEMPLATE
Those TBS tags for the block definition will be deleted during the merging.TEMPLATE...[BlockName;block=begin;params]...TEMPLATE...[BlockName;block=end]...TEMPLATE
Relative Syntax:
The block is defined by a pair of opening-closing XML/HTML tags which is given by a single TBS tag.
This TBS tag will be deleted during the merging.
Remark: You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for more details.
Example:
TEMPLATE...<tag_name...>...[BlockName;block=tag_name;params]...</tag_name...>...TEMPLATE
This TBS tag for the block definition must be placed between the pair of XML/HTML tags.TEMPLATE...<tag_name...>...[BlockName;block=tag_name;params]...</tag_name...>...TEMPLATE
This TBS tag will be deleted during the merging.
Remark: You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for more details.
Simplified Syntax:
An associated TBS field is used to define the block in a relative way (see the relative syntax above).
Remarks:
• You should not repeat the parameter block=... on each fields of the bloc, only one is enough. If you place several of them, this will be accepted by TBS but it may bring confusions about complementary parameters for block.
• You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for more details.
Example:
TEMPLATE...<tag_name...>...[BlockName.ColumnName;block=tag_name;params]...</tag_name...>...TEMPLATE
The TBS tag for the block definition (i.e. the block=... parameter) must be placed between the pair of XML/HTML tags. You are nor obliged to put the parameter block on the first field, it can be any of them inside the zone defined by the block. TEMPLATE...<tag_name...>...[BlockName.ColumnName;block=tag_name;params]...</tag_name...>...TEMPLATE
Remarks:
• You should not repeat the parameter block=... on each fields of the bloc, only one is enough. If you place several of them, this will be accepted by TBS but it may bring confusions about complementary parameters for block.
• You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for more details.
Which syntax to use?
The 'absolute' syntax is rarely used with Visual Editors because TBS tags have often to be placed between two XML/HTML tags. On the other hand, it is convenient for textual editors.
The 'relative' syntax enables you to indicate a block using only one TBS tag. Furthermore, there is no need to hide the TBS tag because it will be deleted during the displaying. This syntax is quite practical.
The 'simplified' syntax is really simple. It enables you to define a TBS block and a TBS Field with only one TBS tag. This syntax is the most current and the most practical.
Tip:
You can use the 'relative' or the 'absolute' syntax with custom tags using the XML/HTML standard.Example:
<custom_tag>Hello [blk1.column1;block=custom_tag], how are you?</custom_tag>
Block's parameters:
| Parameter | Description | |||||||||||||||||||||
| nodata | Indicates a section that is displayed only if there is no data to merge. Example:
For more information about sections, see the chapter 'Sections of blocks'. |
|||||||||||||||||||||
bmagnet=tag or bmagnet=expr |
Indicates an XML/HTML zone which must be deleted if the block is merged with no record (an emprt query, for example, or a PHP Array with no items). Parameter bmagnet supports the same syntax as parameter block, i.e. that expr must be an XML/HTML tag or a TBS extended block expression. Example:
Remark: Value null is not accepted by MergeBlock() method as a data source, and it makes a TBS error instead of deleting the bmagnet zone. If you data source may be null, then you should make a check previously. Example: if (is_null($data)) $data = array();
$TBS->MergeBlock('b1',$data); Versioning: parameter bmagnet is supported since TBS version 3.0. |
|||||||||||||||||||||
| headergrp=colname | Indicates a header section that is displayed each time the value of column colname changes. colname must be a valid column name returned by the data source. Since TBS version 3.3.0, colname can also be a virtual column # or $, and it also support the subitems syntaxe of TBS fields. You can define several headergrp sections with different columns. Placement's order of headergrp sections in the block can modify the result. For more information about sections, see the chapter 'Sections of blocks'. |
|||||||||||||||||||||
| footergrp=colname | Indicates a footer section that is displayed each time the value of column colname changes. See headergrp. | |||||||||||||||||||||
| splittergrp=colname | Indicates a splitter section that is displayed each time the value of column colname changes. See headergrp. | |||||||||||||||||||||
| parentgrp=colname | Indicates a parent section that is displayed each time the value of column colname changes. Unlike other sections, a parentgrp section allows normal sections inside itself. It's a way to define both a header and a footer in one section. | |||||||||||||||||||||
| serial | Indicates that the block is a main block which contains serial secondary blocks. For more information, see the chapter 'serial display (in columns)'. |
|||||||||||||||||||||
| p1=val1 | Indicates the use of a dynamic query. All the occurrences of the string '%p1%' found in the query given to the MergeBlock() method are replaced by the value val1. For more information, see the chapter Subblocks with dynamic queries. If it used without any value, that enables you to merge several blocks of the same name. See "Merging several blocks with the same data" for more details. |
|||||||||||||||||||||
| sub1=column1 | Define the column containing the data for an automatic subblock. For more information, see the chapter Automatic subblocks. |
|||||||||||||||||||||
| ondata=fct_name | Indicates the name of a user Php function that will be executed during the block merging. Since TBS version 3.0, it's also possible to indicate a method of a class. See OOP. The function is called each time a record is taken from the data source. You can use the arguments of such a Php function to edit records before they are merged. The function must have the following syntax: function fct_name($BlockName,&$CurrRec,$RecNum) { ... }
function f_add_column($BlockName,&$CurrRec,$RecNum) {
$CurrRec['len'] = strlen($CurrRec['text']); } Since TBS version 3.6.0, it's possible to limit the allowed PHP functions for parameter ondata. See create a new TBS object. |
|||||||||||||||||||||
| when expr1=expr2 | Make the section conditional and define its condition. A conditional section is displayed only if its condition is verified. Supported operators are:
Example:
[onload;block=div;when [var.x]~='*to*'] ...

The
 block will be displayed only if $x>0. Note: do not confuse parameter when (which works only for TBS blocs or sections) and parameter if (which works only for TBS fields). Thus, parameter when is taken into account only if parameter block exists in the same TBS tag. See conditional blocks for more details. |
|||||||||||||||||||||
| default | Indicates a section of block that must be displayed only if no conditional section of the same block has been displayed. | |||||||||||||||||||||
| several | Indicates that several conditional sections of the block can be displayed if several conditions are true. By default, conditional sections are exclusive. |
Sections of block:
Different blocks having the same name will be regarded as sections of the same block.
Sections can be used to:
- alternate the display (normal sections),
- display something if there is no data (NoData section),
- display a header each time the value of a column changes (grouping sections).
Normal sections:
When you define several normal sections, they will be used alternatively for each record.
NoData section:
The NoData section is a section displayed only if the data source has no records. There can be only one NoData section in a block. The NoData section is defined by adding the parameter nodata.
Grouping sections:
Grouping sections are displayed every time a column's value in the record-set changes. You can define header, footer, splitter or parent sections using parameters headergrp, footergrp, splittergrp, and parentgrp. See block's parameters for more details.
Sections can be used to:
- alternate the display (normal sections),
- display something if there is no data (NoData section),
- display a header each time the value of a column changes (grouping sections).
Normal sections:
When you define several normal sections, they will be used alternatively for each record.
Example:
In this example, the block named 'b1' contains two normal sections. Records will be displayed alternatively with a green background and with a blue background.
| [b1.caption;block=tr] |
| [b1.caption;block=tr] |
In this example, the block named 'b1' contains two normal sections. Records will be displayed alternatively with a green background and with a blue background.
NoData section:
The NoData section is a section displayed only if the data source has no records. There can be only one NoData section in a block. The NoData section is defined by adding the parameter nodata.
Example:
| [b1.caption;block=tr] |
| There is nothing. [b1;block=tr;nodata] |
Grouping sections:
Grouping sections are displayed every time a column's value in the record-set changes. You can define header, footer, splitter or parent sections using parameters headergrp, footergrp, splittergrp, and parentgrp. See block's parameters for more details.
Example:
| Year: [b1.year;block=tr;headergrp=year] | |
| [b1.caption;block=tr] | [b1.amount] |
Conditional sections:
Conditional sections are displayed only if their condition is verified. The condition for display is defined using parameter when. As soon as a section has this parameter, it becomes conditional. See Conditional display for more details.
Conditional sections are displayed only if their condition is verified. The condition for display is defined using parameter when. As soon as a section has this parameter, it becomes conditional. See Conditional display for more details.
Example:
| [b1.name;block=tr] |
| [b1.address;block=tr;when [b1.add_ok]==1] |
Serial display (in columns):
The serial display enables you to display several records inside a block. For this, you have to use a main block and secondary blocks.
Remark:
The serial display also works with sections of block and dynamic queries.
Example:
In this example, main blocks are the blue lines of the table, the secondary blocks are the pink cells.
|
||||
|
||||
|
In this example, main blocks are the blue lines of the table, the secondary blocks are the pink cells.
Syntax:
The main block and its secondary blocks are merged using only one call to the MergeBock() method. The main block must be defined using the parameter serial. The secondary blocks must be nested into the main block. The secondary block's names must be the name of the main block followed by "_" and a number indicating display order.Example:
The corresponding PHP is:
$TBS->MergeBlock('bx',$cnx_id,'SELECT txt FROM t_info ORDER BY txt')
|
The corresponding PHP is:
$TBS->MergeBlock('bx',$cnx_id,'SELECT txt FROM t_info ORDER BY txt')
Empty secondary block:
You can specify a special secondary block that will be used to replace unused secondary blocks (without records). This "Empty" secondary block must have the index 0. It can either be placed inside the main block with the normal secondary block, or alone inside another serial block. The "empty" secondary block is optional.Example:
|
||||
|
Remark:
The serial display also works with sections of block and dynamic queries.
Subblocks:
A subblock is a TBS block nested into another TBS block and that should be displayed as a separated block for each record of its parent block.
They are two different ways to perform subblocks with TBS:
- Automatic subblock: (since TBS 3.5.0) it is when the data of the parent block has a column which contains the ready-to-merge data for the subblock. Automatic subblocks are activated using parameter sub1 in the parent block, and they are merged automatically during the merge of the parent block. No extra MergeBlock() are needed.
See Automatic subblocks for more details.
- Subblock with dynamic query: it is when the data of the subblocks are retrieved using a query which can change for each record of the parent block. Subblocks with dynamic queries need an extra MergeBlock() to perform the merging with their dynamic query. Parameter p1 is also needed in the subblock definition in order to set the values to inject in the dynamic query.
See Subblocks with dynamic queries for more details.
Example:
Parent block record #1
|
|||
Parent block record #2
|
|||
Parent block record #3
|
They are two different ways to perform subblocks with TBS:
- Automatic subblock: (since TBS 3.5.0) it is when the data of the parent block has a column which contains the ready-to-merge data for the subblock. Automatic subblocks are activated using parameter sub1 in the parent block, and they are merged automatically during the merge of the parent block. No extra MergeBlock() are needed.
See Automatic subblocks for more details.
- Subblock with dynamic query: it is when the data of the subblocks are retrieved using a query which can change for each record of the parent block. Subblocks with dynamic queries need an extra MergeBlock() to perform the merging with their dynamic query. Parameter p1 is also needed in the subblock definition in order to set the values to inject in the dynamic query.
See Subblocks with dynamic queries for more details.
Automatic subblocks:
Automatic subblock are supported since TBS version 3.5.0.
You can use automatic subblocks when the data of the parent block has a column which contains the ready-to-merge subdata for the subblock. Set parameter sub1=column in the parent block to define the column which contain the data for the subblock. If you have several subblocks to merge in the same parent block then use parameters sub2, sub3, ... The name of the subblock must be the same as the parent block followed by the suffix _sub1, (or _sub2, _sub3, ...)
The data of the parent block must have a column which contains the data of the subblock. Supported data types are:
- a PHP array
- an object supported by TBS (natively or with a plug-in)
- a text string of values separated by comas (,).
Have the column optional: If you want no error message when the column is omitted in the parent data, then you can set it optional by using parenthesis. This is working only if the parent data is a PHP array. Optional column is supported since TBS version 3.6.0.
Direct subblocks (which are not saved under a column): If you use parameter sub1 by omitting the column name, then TBS will assume that the data for the subblock are available directly on the current record instead of under a column of this record. Direct subblocks are supported since TBS version 3.6.1.
You can use automatic subblocks when the data of the parent block has a column which contains the ready-to-merge subdata for the subblock. Set parameter sub1=column in the parent block to define the column which contain the data for the subblock. If you have several subblocks to merge in the same parent block then use parameters sub2, sub3, ... The name of the subblock must be the same as the parent block followed by the suffix _sub1, (or _sub2, _sub3, ...)
The data of the parent block must have a column which contains the data of the subblock. Supported data types are:
- a PHP array
- an object supported by TBS (natively or with a plug-in)
- a text string of values separated by comas (,).
Example:
Corresponding PHP code:
$TBS->MergeBlock('body',$cnx_id,'SELECT name,spokenlg FROM t_body)
Result of the merge:
Name: [body.name;block=tr;sub1=spokenlg]
|
Corresponding PHP code:
$TBS->MergeBlock('body',$cnx_id,'SELECT name,spokenlg FROM t_body)
Result of the merge:
Name: Peter
|
|||
Name: Paul
|
|||
Name: Jack
|
Have the column optional: If you want no error message when the column is omitted in the parent data, then you can set it optional by using parenthesis. This is working only if the parent data is a PHP array. Optional column is supported since TBS version 3.6.0.
Example:
Name: [body.name;block=tr;sub1=(spokenlg)]
|
Direct subblocks (which are not saved under a column): If you use parameter sub1 by omitting the column name, then TBS will assume that the data for the subblock are available directly on the current record instead of under a column of this record. Direct subblocks are supported since TBS version 3.6.1.
Example of data that can be merged with a direct subblock:
$data = array();
$data['group1'] = array();
$data['group1'][] = array('id'=>1, 'name'=>'peter');
$data['group1'][] = array('id'=>2, 'name'=>'paul');
$data['group2'] = array();
$data['group2'][] = array('id'=>3, 'name'=>'jules');
$data['group2'][] = array('id'=>4, 'name'=>'jim');
Example of direct subblock that can be merged with those data:
$data = array();
$data['group1'] = array();
$data['group1'][] = array('id'=>1, 'name'=>'peter');
$data['group1'][] = array('id'=>2, 'name'=>'paul');
$data['group2'] = array();
$data['group2'][] = array('id'=>3, 'name'=>'jules');
$data['group2'][] = array('id'=>4, 'name'=>'jim');
Example of direct subblock that can be merged with those data:
Group : [body.$;block=tr;sub1]
|
Subblocks with dynamic queries:
Principles of the dynamic queries:
It is possible to use the MergeBlock() method with a dynamic query.
In your template, you have to define a block by adding the parameters p1, p2, p3,... with their values.
The query given to the MergeBlock() method has to contain marks such as %p1%, %p2%, %p3%, ... in order to welcome the values of the parameters p1, p2, p3,...
Each section of the block to be merged that contains a parameter p1 will be computed as a separate block for which the dynamic query is re-executed. The sections of the block that have no parameter p1 are combined with the previous section with a parameter p1.
Example:
Country: France
Country: USA
Corresponding PHP code:
$TBS->MergeBlock('blk',$cnx_id,"SELECT town,country FROM t_geo WHERE (country='%p1%')")
Result of the merge:
Country: France
Country: USA
Country: France
| [blk.town;block=tr;p1='france'] | [blk.country] |
Country: USA
| [blk.town;block=tr;p1='us'] | [blk.country] |
Corresponding PHP code:
$TBS->MergeBlock('blk',$cnx_id,"SELECT town,country FROM t_geo WHERE (country='%p1%')")
Result of the merge:
Country: France
| Paris | france |
| Toulouse | france |
Country: USA
| Washington | us |
| Boston | us |
Use with subblocks:
Dynamic queries enable you to easily build a system of a main-block with subblocks. Here is how you can do it:
- Create a main block, and then a subblock inside the main block.
- Link them by adding to the subblock a parameter p1 whose value is a field from the main block.
- At the PHP side, merge the main block first, and then the subblock.
Example:
Corresponding PHP code:
$TBS->MergeBlock('main',$cnx_id,'SELECT country,cntr_id FROM t_country')
$TBS->MergeBlock('sub',$cnx_id,'SELECT town FROM t_town WHERE (cntr_id=%p1%)')
Result of the merge:
Country: [main.country;block=tr]
|
Corresponding PHP code:
$TBS->MergeBlock('main',$cnx_id,'SELECT country,cntr_id FROM t_country')
$TBS->MergeBlock('sub',$cnx_id,'SELECT town FROM t_town WHERE (cntr_id=%p1%)')
Result of the merge:
Country: France
|
||
Country: Germany
|
||
Country: Spain
|
Remarks:
- The parameter htmlconv=esc enables you to pass protected string values to the query.
- The dynamic queries also work with sections of block and serial display.
Automatic blocks:
Automatic blocks enable you to automatically merge conditional blocks when some events occur.
There are two types of automatic blocks:
- [onload] blocks which are merged automatically when the LoadTemplate() method is called.
- [onshow] blocks which are merged automatically when the Show() method is called.
Automatic blocks are not merged with data ; that's why they cannot have normal sections (non conditional sections) and linked fields. Automatic blocks can have only conditional sections. Conditions are evaluated only once, and they be expressions containing [var] fields.
If you need to have a group of exclusive sections, with or without a default section, you can suffix the [onload] and [onshow] bloc's names with "_" followed by a sub name.
See Conditional sections for more details.
There are two types of automatic blocks:
- [onload] blocks which are merged automatically when the LoadTemplate() method is called.
- [onshow] blocks which are merged automatically when the Show() method is called.
Automatic blocks are not merged with data ; that's why they cannot have normal sections (non conditional sections) and linked fields. Automatic blocks can have only conditional sections. Conditions are evaluated only once, and they be expressions containing [var] fields.
Example:
| [onload;block=tr;when [var.light]=1]Light is ON. |
| [onshow;block=tr;when [var.user]=1] User : [onshow.username] |
If you need to have a group of exclusive sections, with or without a default section, you can suffix the [onload] and [onshow] bloc's names with "_" followed by a sub name.
Example:
| [onload_ligth;block=tr;when [var.light]=1] Light is ON. |
| [onload_ligth;block=tr;when [var.light]=0] Light is OFF. |
| [onload_ligth;block=tr;default] Light is ? |
See Conditional sections for more details.
Subtemplates:
There are two ways to insert subtemplates in your main template.
Primary insertion using parameter file:
This is the best way to simply insert a part contained in another file, like usually done for headers and footers.
The value given to parameter file must be the name of a file existing on the server. You can use an expression with [var] Fields and the [val] keyword which represent the value of the field. If the value is an empty string, then no error message is displayed, it is like parameter file is ignored. This can be used to manage conditional insertion.
Examples:
Contents of the file is inserted at the place of the field, without no char conversion and no TBS protection.
[onload] tags contained in the file are processed at the insertion. [onshow] tags will be merged on the Show() method because they became part of the main template.
The subtemplate can contain any TBS fields, including [var] fields and blocks to be merged. If you intend to merge data with a block defined into a subtemplate, then it's suggested to use parameter file in an [onload] field in order to ensure that the subtemplate is inserted before you call MergeBlock().
You can create a subtemplate in an independent XML/HTML/Text file, and ask TBS to include in the main template only the  part (or another part). This can be done by adding parameter getbody to parameter file in the TBS field of the main template. This technique enables you to work WYSIWYG with your subtemplates.
Primary insertion using parameter file:
This is the best way to simply insert a part contained in another file, like usually done for headers and footers.
The value given to parameter file must be the name of a file existing on the server. You can use an expression with [var] Fields and the [val] keyword which represent the value of the field. If the value is an empty string, then no error message is displayed, it is like parameter file is ignored. This can be used to manage conditional insertion.
Examples:
[onload;file=header.htm]
[onload;file=[var.file_header]]
[onload.sub1;file=[val]]
[onload;file=[var.insert;if [val]=1;then 'header.html';else '']]
[onload;file=[var.file_header]]
[onload.sub1;file=[val]]
[onload;file=[var.insert;if [val]=1;then 'header.html';else '']]
Contents of the file is inserted at the place of the field, without no char conversion and no TBS protection.
[onload] tags contained in the file are processed at the insertion. [onshow] tags will be merged on the Show() method because they became part of the main template.
The subtemplate can contain any TBS fields, including [var] fields and blocks to be merged. If you intend to merge data with a block defined into a subtemplate, then it's suggested to use parameter file in an [onload] field in order to ensure that the subtemplate is inserted before you call MergeBlock().
You can create a subtemplate in an independent XML/HTML/Text file, and ask TBS to include in the main template only the  part (or another part). This can be done by adding parameter getbody to parameter file in the TBS field of the main template. This technique enables you to work WYSIWYG with your subtemplates.
Insertion driven with Php code using parameter subtpl:
Parameter subtpl is useful to manage subtemplate insertion with Php code. Parameter subtpl is active only when used with a parameter script or onformat. It turns the current TBS instance in Subtemplate mode during the script or function execution and can act on a new template without deteriorating the main template.
The Subtemplate mode presents the following characteristics:
When the script or the function ends, the TBS instance returns in normal mode with the main TBS template.
Example with parameter script:
Example with parameter onformat:
Parameter subtpl is useful to manage subtemplate insertion with Php code. Parameter subtpl is active only when used with a parameter script or onformat. It turns the current TBS instance in Subtemplate mode during the script or function execution and can act on a new template without deteriorating the main template.
The Subtemplate mode presents the following characteristics:
| * | Php outputs are displayed at the field's place instead of being immediately sent to the client. For example, using the Php command echo() will insert a text in the main template instead of be directly output it. Using the Show() method will also insert the result of the sub-merge into the main template. |
| * | A reference to the TBS instance is provided by local variable $this or $TBS, whether you use parameter script or onformat. This variable be used for new submerges without deteriorating the main template. The Show() method won't stop any script execution during the Subtemplate mode like it does by default in normal mode. |
When the script or the function ends, the TBS instance returns in normal mode with the main TBS template.
Example with parameter script:
| HTML: | [onload.file;script=specialbox.php;subtpl] |
| PHP script: | <?php echo('* Here include a subtemplate *'); $this->LoadTemplate($CurrVal); $this->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1'); $this->Show(); ?> |
| Remarks: | $CurrVal is a local variable provided by TBS when using parameter script ; this variable is a reference to the value of the field currently merged. In the example above, $CurrVal has the value of the global variable $file. You can replace it, for example, by the name of the subtemplate to load (for example: 'mysubtpl.htm'). See parameter script for more information. |
Example with parameter onformat:
| HTML: | [onload.user_mode;onformat=f_user_info;subtpl] |
| PHP user function: | function f_user_info($FieldName,&$CurrVal,&$CurrPrm,&$TBS) { if ($CurrVal==1) { // User is logged in $TBS->LoadTemplate('user_info.htm'); $TBS->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1'); $TBS->Show(); } else { // User not logged in echo('You are not logged in.'); } } |
| Remarks: | $CurrVal is a variable declared as an argument of the function. It's TBS that is in charge to call this function making $CurrVal referring to the value of the fields currently merged. In this example above, $CurrVal is equal to the global variable $user_mode. In the same way, variable $CurrPrm is a reference to the array of parameters of the field currently merged, and $TBS is a reference to the TinyButStrong instance currently used. See parameter onformat for more information. |
Conditional display overview:
TinyButStrong offers several tools for conditional display for both fields and blocks.
Conditional fields
For any TBS fields you can use parameters for conditional display, recalled below.
Conditional sections
You can use conditional sections any TBS block (data block or automatic block). A conditional section is a section which has a parameter when defining a condition, or parameter default. At the block's merging, each when condition of conditional sections is evaluated until one is verified. As soon as one when condition is verified, its conditional section is kept and other conditional sections are deleted. If no when condition is verified, then the default section is displayed if it exists.
The case of data blocks:
If it is a data block, it means a block merged with MergeBlock(), then the conditional sections are reassessed for each record. It is even possible to define a data block with only conditional sections, with no standard section.
Defining the conditions:
The conditions defined into parameters when can be expressions that contain [var] fields et and linked fields (if it is a data block). See parameter when for more details about operators supported by TBS.
Section exclusivity:
By default conditional sections are exclusive inside a block. It means only one conditional section of a block can be displayed. But if you want a block to have non-exclusive conditional sections, you can use parameter several on the first conditional section. With this parameter, all conditions are evaluated and each true condition makes its section to be displayed.
Example with a data block:
Example with an automatic block:
Conditional fields
For any TBS fields you can use parameters for conditional display, recalled below.
| Parameter | Description |
| . (dot) | Display an Html unbreakable space if the field value is empty. |
| ifempty=value2 | Display value2 if the field value is empty. |
| magnet=tag | Delete a tag or a pair of tags if the field value is empty. |
| if condition then value1 else value2 |
Display value1 or value2 depending on whether the condition is verified or not. |
| frm=format1|format2|format3|format4 | Changes the numeric format or date/time format depending on whether the value is positive, negative, zero or empty. |
Example:
[onshow.error_id;if [val]=0;then 'no error';else 'error found']
[onshow.error_id;if [val]=0;then 'no error';else 'error found']
Conditional sections
You can use conditional sections any TBS block (data block or automatic block). A conditional section is a section which has a parameter when defining a condition, or parameter default. At the block's merging, each when condition of conditional sections is evaluated until one is verified. As soon as one when condition is verified, its conditional section is kept and other conditional sections are deleted. If no when condition is verified, then the default section is displayed if it exists.
The case of data blocks:
If it is a data block, it means a block merged with MergeBlock(), then the conditional sections are reassessed for each record. It is even possible to define a data block with only conditional sections, with no standard section.
Defining the conditions:
The conditions defined into parameters when can be expressions that contain [var] fields et and linked fields (if it is a data block). See parameter when for more details about operators supported by TBS.
Section exclusivity:
By default conditional sections are exclusive inside a block. It means only one conditional section of a block can be displayed. But if you want a block to have non-exclusive conditional sections, you can use parameter several on the first conditional section. With this parameter, all conditions are evaluated and each true condition makes its section to be displayed.
Example with a data block:
| Name: [b1.Name;block=tr] | standard section |
| Address: [b1.add_line1;block=tr;when [b1.address]=1] [b1.add_line2] [b1.add_zip] - [b1.add_town] |
conditional section |
| No address.[b1;block=tr;default] | default conditional section (optional) |
Example with an automatic block:
| [onload_err;block=tr;when [var.email]='';several] Your email is empty. |
| [onload_err;block=tr;when [var.name]=0] Your name is empty. |
| [onload_err;block=tr;default] All is ok. |
Coding plug-ins:
You can add features to TinyButStrong using plug-ins. The database plug-ins simply enable the method MergeBlock() to recognize new types of database. The other plug-ins enable you to add features to TBS or to modify its main methods in order to make it more specialized.In both cases, a plug-in is made of a set of PHP functions or one PHP class which have to fit with a special syntax expected by TBS. Some plug-ins are proposed for download at the TinyButStrong web site.
Database plug-ins:
Versioning: database plug-ins are supported since TBS version 1.8.
A database plug-in enables the method MergeBlock() to recognize a new type of database.
When you have a call such as $TBS->MergeBlock($BlockName, $Source, $Query), the MergeBlock process is first examining $Source to see if its type is supported.
Database plug-in based un user functions:
When the MergeBlock process meet a type of value for $Source which is not supported in native, it determines the TBS Id corresponding to that type. Then it looks for the user functions corresponding to that TBS Id.
How to determine the TBS Id:
The TBS Id is a string identifier determined by the argument $Source.
If $Source is a string => the TBS Id is that string.
If $Source is a PHP resource => the TBS Id is the name of the resource's type.
If $Source is an object => the TBS Id is the name of the class.
For some convenience, if the TBS Id contains spaces (' '), it is cut. If the TBS Id contains '-', they are replaced with '_'.
For example, a PHP variable for a Sybase connection is typed as Resource and its resource name is 'sybase-db link'. The corresponding TBS Id is 'sybase_db'.
How to build the plug-in for a TBS Id:
The plug-in is made of 3 user functions which must have specific names.
The following function names are made for a TBS Id which is 'tbsid'. For another TBS Id, you just have to rename the functions.
You can found several examples of database plug-in at the TinyButStrong web site.
Synopsis:
function tbsdb_tbsid_open(&$Source, &$Query)
Database plug-in based on object:
When the MergeBlock process meet of value for $Source which is an object, and if that object has a method named tbsdb_open(), then it assumes that the object is a database plug-in.
The object must have at least the 3 methods tbsdb_open(), tbsdb_fetch() and tbsdb_close(). There can be other methods and properties, but those 3 methods must have the same syntax and the same feature as the user functions described above.
Synopsis:
class clsTbsPlugin {
function tbsdb_open(&$Source, &$Query)
function tbsdb_fetch(&$Rs [,$RecNum])
function tbsdb_close(&$Rs)
}
Database plug-in based on property ObjectRef:
When the MergeBlock process meet a value for $Source which is a string beginning with '~' then it assumes that property $TBS->ObjectRef is a database plug-in based on object (see OOP). The object must have the same requirements as a database plug-in based on objet described above, but the names of the methods can be different.
Example:
$TBS->MergeBlock($BlockName,'~dbkey',$Query);
class clsTbsPlugin {
function dbkey_open(&$Source, &$Query)
function dbkey_fetch(&$Rs [,$RecNum])
function dbkey_close(&$Rs)
}
A database plug-in enables the method MergeBlock() to recognize a new type of database.
When you have a call such as $TBS->MergeBlock($BlockName, $Source, $Query), the MergeBlock process is first examining $Source to see if its type is supported.
| • | If $Source is a type of resource known in native by TBS, then the MergeBlock process doesn't need any plug-in help, it will retrieve the data by its own. |
| • | If $Source is an object having a method named tbsdb_open() then the MergeBlock process assumes that the object is a database plug-in and use it to retrieve the data. (See more details below) |
| • | If $Source is a string beginning with '~' then the MergeBlock process assumes that property $TBS->ObjectRef is a database plug-in and use it to retrieve the data. (See more details below) |
| • | If $Source is something else then the MergeBlock process is trying to found the plug-in made by user functions that correspond to the type of $Source. (See more details below) |
Database plug-in based un user functions:
When the MergeBlock process meet a type of value for $Source which is not supported in native, it determines the TBS Id corresponding to that type. Then it looks for the user functions corresponding to that TBS Id.
How to determine the TBS Id:
The TBS Id is a string identifier determined by the argument $Source.
If $Source is a string => the TBS Id is that string.
If $Source is a PHP resource => the TBS Id is the name of the resource's type.
If $Source is an object => the TBS Id is the name of the class.
For some convenience, if the TBS Id contains spaces (' '), it is cut. If the TBS Id contains '-', they are replaced with '_'.
For example, a PHP variable for a Sybase connection is typed as Resource and its resource name is 'sybase-db link'. The corresponding TBS Id is 'sybase_db'.
How to build the plug-in for a TBS Id:
The plug-in is made of 3 user functions which must have specific names.
The following function names are made for a TBS Id which is 'tbsid'. For another TBS Id, you just have to rename the functions.
You can found several examples of database plug-in at the TinyButStrong web site.
Synopsis:
function tbsdb_tbsid_open(&$Source, &$Query)
This function is called one time by the MergeBlock process, before the other user functions.
It is supposed to use $Source and $Query to open a recordset, and return a reference of that recordset.
function tbsdb_tbsid_fetch(&$Rs [,$RecNum])It is supposed to use $Source and $Query to open a recordset, and return a reference of that recordset.
This function is called several times by the MergeBlock process, as many times as there are data to fetch from the query.
This function should return the next record as an associative array (column name=> value), or return false if there is no record left.
$Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.
$RecNum can be useful for some database type such as Oracle, for which the number of the record is needed to retrieve it.
function tbsdb_tbsid_close(&$Rs)This function should return the next record as an associative array (column name=> value), or return false if there is no record left.
$Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.
$RecNum can be useful for some database type such as Oracle, for which the number of the record is needed to retrieve it.
This function is called on time by the MergeBlock process, after the other user functions.
This function should close the recordset properly.
$Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.
This function should close the recordset properly.
$Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.
Database plug-in based on object:
When the MergeBlock process meet of value for $Source which is an object, and if that object has a method named tbsdb_open(), then it assumes that the object is a database plug-in.
The object must have at least the 3 methods tbsdb_open(), tbsdb_fetch() and tbsdb_close(). There can be other methods and properties, but those 3 methods must have the same syntax and the same feature as the user functions described above.
Synopsis:
class clsTbsPlugin {
function tbsdb_open(&$Source, &$Query)
function tbsdb_fetch(&$Rs [,$RecNum])
function tbsdb_close(&$Rs)
}
Database plug-in based on property ObjectRef:
When the MergeBlock process meet a value for $Source which is a string beginning with '~' then it assumes that property $TBS->ObjectRef is a database plug-in based on object (see OOP). The object must have the same requirements as a database plug-in based on objet described above, but the names of the methods can be different.
Example:
$TBS->MergeBlock($BlockName,'~dbkey',$Query);
class clsTbsPlugin {
function dbkey_open(&$Source, &$Query)
function dbkey_fetch(&$Rs [,$RecNum])
function dbkey_close(&$Rs)
}
Other plug-ins:
Versioning: plug-ins are supported since TBS version 3.0.
Coding a plug-in using a PHP class:
• Plug-in's key:
Each plug-in has a plug-in key which is the name of its Php class. This key must be given to the method PlugIn() when you use it. Thus, it is recommended to define a PHP constant for the plug-in's key (see example below).
• Plug-in events:
A TBS plug-in must be a PHP class which contains one or several specific methods that will be recognized and plugged by TBS. Those specific methods are called plug-in events because they are executed automatically by TBS when the corresponding event occurs. A TBS plug-in can also have other methods and properties for internal purpose. A TBS plug-in must have at least the OnInstall event.
For example:
See the PHP file "tbs_plugin_syntaxes" to have all plug-in events, their usage and expected arguments. There is also a list of supported events at the bottom of this section.
The OnInstall event is special. It has to return an array with all activated events for the current plug-in (see the PHP file "tbs_plugin_syntaxes"). The OnInstall event is called when the plug-in is installed at the TBS instance.
This event can be called in three situations:
- When using method PlugIn() with the plug-in's key for the first time.
- When using method PlugIn() with the plug-in's key and the argument TBS_INSTALL.
- When a new TBS instance is created, if the plug-in's key has be added to the global array $_TBS_AutoInstallPlugIns[] (see file "tbs_plugin_syntaxes.php" for more details).
Property ->TBS:
As soon as the plug-in is installed on the TBS instance, a property ->TBS is automatically added to the plug-in, its value is a reference to the parent TBS instance. Remember this because this property can be very useful inside the plug-in's code.
Coding a plug-in using PHP functions:
The plug-ins' key is a string that you choose and which will be used for naming the function. It is recommended to define a PHP constant for the plug-in's key (see example below).
The plug-in events are coded using functions, and they names must be the string 'tbspi_', followed by the plug-in's key, followed by '_' and the event's name.
Example:
All the rest works like for plug-in coded with a class. You must have at least the event OnInstall created, and it works the same way.
Remark: PHP functions are often faster than methods, but they don't let you having a ->TBS property to reach the parent TBS instance.
List of plug-in events:
Coding a plug-in using a PHP class:
• Plug-in's key:
Each plug-in has a plug-in key which is the name of its Php class. This key must be given to the method PlugIn() when you use it. Thus, it is recommended to define a PHP constant for the plug-in's key (see example below).
• Plug-in events:
A TBS plug-in must be a PHP class which contains one or several specific methods that will be recognized and plugged by TBS. Those specific methods are called plug-in events because they are executed automatically by TBS when the corresponding event occurs. A TBS plug-in can also have other methods and properties for internal purpose. A TBS plug-in must have at least the OnInstall event.
For example:
// TBS plug-in XXX
define('TBS_XXX','clsTbsPlugIng_XXX'); // That is the plug-in's key
class clsTbsPlugIng_XXX() {
function OnInstall(...) {...} // That is the OnInstall event
...
}
define('TBS_XXX','clsTbsPlugIng_XXX'); // That is the plug-in's key
class clsTbsPlugIng_XXX() {
function OnInstall(...) {...} // That is the OnInstall event
...
}
See the PHP file "tbs_plugin_syntaxes" to have all plug-in events, their usage and expected arguments. There is also a list of supported events at the bottom of this section.
The OnInstall event is special. It has to return an array with all activated events for the current plug-in (see the PHP file "tbs_plugin_syntaxes"). The OnInstall event is called when the plug-in is installed at the TBS instance.
This event can be called in three situations:
- When using method PlugIn() with the plug-in's key for the first time.
- When using method PlugIn() with the plug-in's key and the argument TBS_INSTALL.
- When a new TBS instance is created, if the plug-in's key has be added to the global array $_TBS_AutoInstallPlugIns[] (see file "tbs_plugin_syntaxes.php" for more details).
Property ->TBS:
As soon as the plug-in is installed on the TBS instance, a property ->TBS is automatically added to the plug-in, its value is a reference to the parent TBS instance. Remember this because this property can be very useful inside the plug-in's code.
Coding a plug-in using PHP functions:
The plug-ins' key is a string that you choose and which will be used for naming the function. It is recommended to define a PHP constant for the plug-in's key (see example below).
The plug-in events are coded using functions, and they names must be the string 'tbspi_', followed by the plug-in's key, followed by '_' and the event's name.
Example:
define('TBS_XXX','xxx');
function tbspi_xxx_OnInstall(...) {...}
...
function tbspi_xxx_OnInstall(...) {...}
...
All the rest works like for plug-in coded with a class. You must have at least the event OnInstall created, and it works the same way.
Remark: PHP functions are often faster than methods, but they don't let you having a ->TBS property to reach the parent TBS instance.
List of plug-in events:
| Plug-in Events | Description | |
| • | OnInstall | Executed automatically when the plug-in is called for the first time, or when PlugIn() method is called with the specific argument for installing. |
| • | OnCommand | Executed when PlugIn() method is called. This is a way to execute any user command specific to the plug-in. |
| • | BeforeLoadTemplate |
Executed when LoadTemplate() method is called. Can cancel TBS basic process. |
| • | AfterLoadTemplate | Executed at the end of LoadTemplate(). |
| • | BeforeShow | Executed when Show() method is called. Can cancel TBS basic process. |
| • | AfterShow | Executed at the end of Show(). |
| • | OnData | Executed each time a record of data is retrieved for a MergeBlock() process. (similar to parameter 'ondata' but for every block) |
| • | OnFormat | Executed each time a fields is being merged. (similar to parameter 'onformat' but for every fields) |
| • | OnOperation | Executed each time parameter 'ope' is defined with an unsupported keyword. |
| • | OnCacheField | Executed each time a field is put in the cache of a Block definition. (supported since TBS 3.6.0) |