Site: | www.tinybutstrong.com |
Date: | 2024-05-08 |
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 °~°.
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.
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.
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.
Example 1:
Html Template | Php Program | Result |
---|---|---|
<html> <body> [onshow.message] </body> </html> |
<?php include_once('tbs_class.php'); $TBS = new clsTinyButStrong; $TBS->LoadTemplate('template.htm'); $message = 'Hello'; $TBS->Show(); |
<html> <body> Hello </body> </html> |
Example 2:
Html Template | Php Program | Result |
---|---|---|
<table> <tr><td>[blk.val;block=tr]</td></tr> </table> |
<? include_once('tbs_class.php'); $TBS = new clsTinyButStrong; $TBS->LoadTemplate('template.htm'); $list = array('X','Y','Z'); $TBS->MergeBlock('blk', $list); $TBS->Show(); |
<table> <tr><td>X</td></tr> <tr><td>Y</td></tr> <tr><td>Z</td></tr> </table> |
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();
Here is the description of the TinyButStrong 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 as of version 3.8.0: $TBS = new clsTinyButStrong({array Options})
Argument | Description |
---|---|
Options | An array of options to set for the option of the template engine. See all available options at the SetOption section. |
Examples:
$TBS1 = new clsTinyButStrong; // default behavior $TBS2 = new clsTinyButStrong( array('chr_open'=>'{', 'chr_close'=>'}') ); // TBS tags will be like {var.x} instead of [var.x] $TBS3 = new clsTinyButStrong( array('var_prefix'=>'tbs_fct_') ); // TBS will display only PHP global variables beginning with 'tbs_var_' $TBS4 = new clsTinyButStrong( array('fct_prefix'=>'tbs_fct_') ); // TBS will call only PHP function beginning with 'tbs_fct_'
Versioning:
Before TBS version 3.8.0, the syntax to create a new TBS object
was:
$TBS
= new clsTinyButStrong({string chr_delim
{, string var_prefix {, string fct_prefix}}});
where:
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 = ''])
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. Will set the charset option. |
If the file is not 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.
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.
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
option is modified, without doing any other action. (deprecated
since TBS version 3.8.0, use SetOption()
instead)
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
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).
Versioning: since TBS version 3.12.0, MergeBlock() return false if no block and no field have been merged. Before that it returned 0.
TinyButStrong supports several data source types in native:
Php data: | an array, a string, a number, an IteratorAggregate |
---|---|
PHP Databases Drivers: | MySQL, PostgreSQL, SQLite, PDO |
PHP Library Connectors: | Doctrine DBAL, Zend_Db |
You can also add a new one: 'database plug-ins'.
Syntax: mixed $TBS->MergeBlock(string BlockName, mixed Source [, string Query = '' [, mixed QryPrms = false]])
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.
|
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:
Block's name: | block1 |
Columns returned by the query: | column1, column2, column3 |
Linked TBS Fields: | [block1.column1], [block1.column2], [block1.column3] |
If no block's definition is found in the template (that is parameter block is never used on the block's fields), 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.
In a TBS field, you can refer to an array item, a method or a property using subnames:
An item of an array | [block1.arr1.key1] |
A property of an object: | [block1.obj1.propZ] |
A method of an object | [block1.obj1.methA()] |
A method of an object with argument : | [block1.obj1.methA(arg1)] |
Cascading subnames: | [block1.arr1.key2.methA().PropZ] |
This assumes the parent's name of a subname refers to an array or an object.
Remarks :
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.
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');
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.$]
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). |
Zend DB Adapter | A Zend DB Adapter object. Supported since TBS version 3.8.0. | An SQL statement. Optional argument QryPrms can be used like with $db->execute($sql, $prms). |
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 | - | |
SQLite3 | An SQLite3 object | An SQLite statement. You can use the
optional argument QryPrms
in order to bind
values. Exemple #1: array("value1", "values2"). Exemple #2: array(':p1'=>"value1", 'p2' => "value2"). Exemple #3: array(':p1'=>array("value1", SQLITE3_TEXT)). |
An SQLite3Stmt object | You can use the optional argument Query in order to bind values. See examples above. | |
An SQLite3Result object | - | |
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. |
(*) See explanations in the chapter below.
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');
Versioning: the keyword 'assigned' is supported since TBS version 3.5.
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 argument Source has to be equal to 'num'. 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. |
Examples:
$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));
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');
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 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 VarRef or ObjectRef.
Syntax when Query is a string:
In the first syntax, 'varref_key'
is a key under $TBS->VarRef.
(Thus VarRef must be an associated array). By default $TBS->VarRef
is a reference on $GLOBAL. See
property VarRef for more details.
In the second syntax, 'objref_key'
is a key under $TBS->ObjectRef.
(Thus ObjectRef must be an associated array). See property ObjectRef
for more details.
Sub items like [key] represents a key assuming the previous item
is an associative array.
Sub items like ->methA()
represents a method assuming the previous item is an object. You
can use argments ; for example : ->methA(arg1)
Sub items like ->PropZ
represents a property assuming the previous item is an object.
The final item must be an array.
Example:
$TBS->MergeBlock('block1','array','days[mon]');
It is possible to represent variable's name without items.
Example:
$TBS->MergeBlock('block1','array','days');
There are two advantages in using a string to represent the array:
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.$]
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 ... |
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:
Example: |
[0] => (['column1']=>value1-0 ; ['column2']=>value2-0 ; ...) [1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...) [2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...) ... |
The returned Record Set consists of the columns 'column1', 'column2',... with their associated values.
Terminates the merge.
Syntax: $TBS->Show([int Render = false])
The Show() method performs the following actions:
The Render allows to adjust the behavior of the Show() method. See the Render option for more information.
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 = false [, boolean DefTags = true [, mix ReplaceWith = false]]])
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. |
Versioning:
Replaces one or several TBS Fields with a fixed value or by calling a user function. Each TBS fields having the specified base name will be merged.
Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).
It is also possible to merge the special [onload], [onshow] and [var] (see below).
Syntax: $TBS->MergeField(string BaseName, mixed DataOrFct [, boolean FctMode = false [, array DefaultPrm = false ]])
Argument | Description |
---|---|
BaseName | Base name of the TBS Fields. For example 'account'. |
DataOrFct | The value to display (or a string that represent the name of a user function if the argument FctMode is set to true). |
FctMode | Default value is false. Indicates that the value to display is calculated by a user function. If this argument is set to true, then DataOrFct 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. |
If argument FctMode is omitted or false, then TBS assumes DataOrFct is some data. It can be a numeric, a 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'));
If you have subdata, MergeField also support subnames.
If argument FctMode is true, then TBS assumes DataOrFct is the name of a global function. It can also be a method, see OOP for more details.
TBS calls this function for each field found in the template. The 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'] ; }
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 automatic fields is supported since TBS version 3.0. It replaces the old method MergeSpecial() which is not supported anymore.
Set one or several TBS options. See the list and desciptions of
options below.
Some of the TBS options are a new way of setting old
TBS features.
Versioning: methods SetOption() is supported since TBS version 3.8.0.
$TBS->SetOption(string $option_name, mixed $value)
Syntax for an array of options:
$TBS->SetOption(array $options)
Examples:
$TBS->SetOption('charset', false); // change the Charset option $TBS->SetOption( array('chr_open'=>'{', 'chr_close'=>'}') ); // change several options
Syntax 1: $TBS->SetOption(string
$option_name, string $item, mixed $value)
Syntax 2: $TBS->SetOption(string
$option_name, array $values)
Examples:
$TBS->SetOption('tpl_frms', 'curr', '0,000.0'); // add item 'curr' to the Template Formats $TBS->SetOption('tpl_frms', 'curr', null); // delete item 'curr' from the Template Formats $TBS->SetOption('tpl_frms', null); // delete all items from the Template Formats $TBS->SetOption('include_path', 'tpl/english'); // add one path to the TBS include_path $TBS->SetOption('include_path', 'tpl/english', null); // delete one path from the TBS include_path $TBS->SetOption('include_path', null); // delete all pathes from the TBS include_path
Option name | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
var_prefix |
Limit the usage of automatic fields ([onload] [onshow] and [var]) in templates. TBS will display only keys prefixed with var_prefix. Other keys will produce an error message. The default value is '' (empty string) which means no limitation. Example: if option var_prefix
is set to 'my' then |
||||||||
fct_prefix |
Limit the usage of custom PHP functions (relative to parameters onformat and ondata) in templates. TBS will call only PHP function prefixed with fct_prefix. Other functions will produce an error message. The default value is '' (empty string) which means no limitation. |
||||||||
noerr |
Enables you to avoid all TinyButStrong error messages. Default value is false. The errors that were not displayed can however be returned with the special automatic field [onshow..error_msg]. Furthermore you can check the presence of error using property $TBS->ErrCount which counts TBS errors regardless of option noerr. When the noerr option is set to false, error messages are concatened in property $TBS->ErrMsg. Option noerr is a bit different from the field's parameter noerr. Option noerr applies for any TBS error and will avoid the merge of a block or a field which has an error. While parameter noerr ensures the merge. Option noerr is useful in two cases:
Versioning: the special automatic field [onshow..error_msg] is supported since TBS version 3.5.0. |
||||||||
auto_merge |
A combination of the couple of options onload and onshow. Default value is true. |
||||||||
onload |
Cancel the automatic processing of [onload] fields. This option accept only values true of false. Default value is true. This can be very useful especially, but not only, for some TBS plug-ins. |
||||||||
onshow |
Cancel the automatic processing of [onshow] fields.This option accept only values true of false. Default value is true. This can be very useful especially, but not only, for some TBS plug-ins. Note that for compatibility, free [var] fields are automatically processed even if option onshow is set to false. |
||||||||
att_delim |
This option tells which is string delimiter to be choosen by parameter att when a new Xml/Html attribute has to be created. The supported values are :
|
||||||||
protect |
Protects all merged items by replacing the characters '[' with their corresponding XML/HTML code '['. Default value is true. 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. |
||||||||
charset |
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. In a Html page, the template charset is defined at the beginning of the file, in the attribute 'content' of a <Meta> tag. The default value is '' (empty string) which is the correct value for charsets 'UTF-8', 'ISO-8859-1' (Latin 1), 'ISO-8859-15', 'cp866', 'cp1251', 'cp1252', and 'KOI8-R'. See the PHP function htmlspecialchars() for other charsets and technical explanations. No character conversion:If you use value false for
the charset option, then data
will to not be converted when merged into the model. 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 charset option with the syntax '=myfunction'. Since TBS version 3.0,
it's also possible to indicate a method of a class (see OOP). 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('<br />', '<text:line-break/>',$x); } return $x; } |
||||||||
chr_open |
Opening delimiter for TBS fields. 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. |
||||||||
chr_close |
Closing delimiter for TBS fields. Must be only one character. |
||||||||
tpl_frms | Enables you to define formats in the template that you can reuse for parameter frm. It is the same feature as parameter tplfrms, but option tpl_frms is defined in the PHP side, while parameter tplfrms is defined in the template side. You can manage this option using the syntax for options that are array. | ||||||||
prm_combo |
Enables you to define a set of parameters that can be
applied at the template side using parameter combo. A combo definition can use parameter combo. Examples: // simple example $TBS->SetOption('prm_combo', 'my_combo_1', array('att'=>'div#data-date', 'frm'=>'yyyy-mm-dd', 'magnet'=>'div', 'enlarge'=>'span')); // example using a parameter that is supposed to have no value (value true used instead) $TBS->SetOption('prm_combo', 'my_combo_2', array('noerr'=>true, 'magnet'=>'div')); // example using multiple if/then parameters $TBS->SetOption('prm_combo', 'my_combo_2', array('if'=>array('[val]=1', '[val]=2', '[val]=3'), 'then'=>array('One', 'Two', 'Three'), 'else'=>'More'); Versioning: option 'prm_combo' is supported since TBS version 3.11.0. |
||||||||
include_path |
Enables you to define one or several paths where TBS should
search files for method LoadTemplate(),
parameters script
and file. |
||||||||
block_alias | Enables you to
define block alias. You can manage this option using the syntax for options that are array. |
||||||||
parallel_conf | Enables you to
define a configuration for parallel
merge. You can manage this option using the syntax for options that are array. |
||||||||
render |
Indicates how the merging ends. The value must be a combination of the following constants. The default value is (TBS_OUTPUT + TBS_EXIT). The Render property changes the behavior of the Show() method.
|
||||||||
methods_allowed |
Allow methods in automatic fields. The default value is false. If you set this option to true, then automatic fields can call methods of its sub items. It is a security point to not allow methods by default on automatic fields because all global variables can be called by automatic fields until VarRef is redefined. Example of automatic field calling a method: [onshow.my_objet.my_method] Versioning: option 'methods_allowed' is supported since TBS version 3.8.2. |
||||||||
scripts_allowed |
Allow to use parameter
script. The default value is false. This is a security option. Versioning: option 'scripts_allowed' is supported since TBS version 3.14.0. |
||||||||
old_subtemplate |
Use the old sub-template technic of TinyButStrong 3.8.2 or lower. Since version 3.9.0 there is a more robust technic. The old technic consists in calling PHP output buffering. Use this option if you encounter strange behaviors with your old code when using parameter script and subtpl. This may happen only if you called the PHP command echo() in the sub-template script, which is quite rare. Versioning: option 'old_subtemplate' is supported since TBS version 3.9.0. |
Some TBS options are a new way of setting old TBS features.
The old features are still suported for compatibility, but they
become deprecated. It is better to use the TBS options.
Option | Corresponding old feature | Supported since version |
---|---|---|
var_prefix, fct_prefix, chr_open, chr_close | was arguments of the instanciation: $TBS = new clsTinyButStrong() | 2.0.0 |
charset | was an arguments of the method $TBS->LoadTemplate() | 1.90 |
render | was a dedicated property: $TBS->Render | 1.60 |
protect | was a dedicated property: $TBS->Protect | 1.64 |
noerr | was a dedicated property: $TBS->NoErr | 3.0.0 |
onload | was a dedicated property: $TBS->OnLoad | 3.6.0 |
onshow | was a dedicated property: $TBS->OnShow | 3.6.0 |
att_delim | was a dedicated property: $TBS->AttDelim | 3.5.0 |
Return the value of a TBS option.
Syntax: mixed $TBS->GetOption(string $option_name)
For supported options names, see method SetOption().
Versioning: methods GetOption() is supported since TBS version 3.8.0.
Reset the VarRef property.
By default, VarRef refers to the PHP global variable $GLOBALS.
Syntax: $TBS->ResetVarRef(boolean $to_globals)
Argument | Description |
---|---|
$to_globals | Indicates if the property VarRef
refers to $GLOBALS or is a new empty array. - if $to_globals is true then VarRef refers to $GLOBALS. - if $to_globals is false then VarRef is a new empty array. |
Get an item value in the VarRef property.
This function uniformizes the way to get a VarRef item, whether VarRef refers to $GLOBALS or not.
Syntax: mixed $TBS->GetVarRefItem(string $key , mixed $default = null)
If VarRef if a dedicated array, then this function is the same as doing $TBS->VarRef[$key] ?? $default;
Versioning: methods GetVarRefItem() is supported since TBS version 3.13.0.
Set an item value in the VarRef property.
This function uniformizes the way to set a VarRef item, whether VarRef refers to $GLOBALS or not.
Syntax: $TBS->SetVarRefItem(string $key , mixed $value)
Syntax for an array of items: $TBS->SetVarRefItem(array $items)
If VarRef if a dedicated array, then this function is the same as doing $TBS->VarRef[$key] = $value;
Versioning: methods SetVarRefItem() is supported
since TBS version 3.13.0.
The syntax for an array of items is supported since TBS version
3.13.1.
Replace a set of simple TBS fields in the template with new definitions prepared at the PHP side. Note than this function does not merges any field ; it only replaces the definition of fields.
This is useful when you miss some place in the template for certain fields ; and also to delete some fields.
Syntax: mixed $TBS->ReplaceFields(array $fields [, string $block_name = false])
Argument | Description |
---|---|
$fields | An associative where keys are the
names of the simple TBS tags to replace in the template ; and
values are the new definition of the field. The new definition of the field can be either : - an array of TBS parameters, with the same principle as SetOption('prm_combo') - a string that will replace the full TBS field's definition. |
$block_name | (optional) A block's name to add as prefix of all field's names (only if the new definition is an array of parameter) |
In the template, the simple TBS fields to replace must have no parameters. Fields with parameters won't be replaced.
If the new definition of the field is an array of parameter, then the field's name is unchanged unless you use the special parameter 'name'.
Example:
// [s1] will be replaced with [s1;enlarge=div;magnet=table;frm=0.00;noerr] // [s2] will be replaced with [onshow.x2;frm=0.00] // [s3] will be replaced with [onshow.x3;noerr] // [s4] will be deleted $TBS->ReplaceFields( array( 's1' => array('enlarge' => 'div', 'magnet' => 'table', 'frm' => '0.00', 'noerr' => true), 's2' => array('name' => 'onshow.x2', 'frm' => '0.00'), 's3' => '[onshow.x3;noerr]', 's4' => '', ));
Versioning: methods ReplaceFields() is supported since TBS version 3.11.0.
Return the value of an XML/HTML attribute in the template.
Syntax: mixed $TBS->GetAttValue(string $field_name [, boolean $delete = true])
Argument | Description |
---|---|
$field_name | The name of a TBS field in the template. The field must have parameter att. |
$delete | (Optional, true by default) Indicate if the TBS field must be deleted after it is found. |
The function will search the first TBS field with the given name, and then search for the attribute targeted by its parameter att.
The function takes in acount only the first field that is met. The TBS field is deleted if $delete is true, but is remains unmodified in the template if $delete is false.
The function return:
Versioning: methods GetAttValue() is supported since TBS version 3.11.0.
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.
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);
Remark: when you call a plug-in's command for the first time this plug-in is automatically installed on the TBS instance ($TBS).
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_XXX, TBS_XXX);
Remarks:
Versioning: the method PlugIn() is supported since TBS version 3.0.
Property VarRef is the array of the items that will be merged with automatic fields ([onload], [onshow] and [var]).
Syntax: array $TBS->VarRef
By default $TBS->VarRef refers to the special $GLOBALS variable of PHP. This is for compatibility reasons, but it is recommended to use another array instead (see below).
You can set $TBS->VarRef to be a new empty array using the method $TBS->ResetVarRef(false);
You can also set $TBS->VarRef to be a reference to your own array : $TBS->VarRef =& $my_array;
Notes:
Example when VarRef is a custom array (recommended):
$TBS->ResetVarRef(false); // VarRef is now a new empty array $TBS->VarRef['my_item'] = "my value"; $TBS->SetVarRefItem('my_item', "my value"); // same as above but ensure the compatibility with any situation
Example when VarRef is attached to $GLOBALS (by default):
$TBS->VarRef['my_item'] = "my value";// this will raise an error as of TBS version 3.13.0 $GLOBALS['my_item'] = "my value"; $TBS->SetVarRefItem('my_item', "my value"); // same as above but ensure the compatibility with any situation
Versioning:
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:
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
Example of an automatic merging:
$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
Notes:
Versioning: property Assigned is supported since TBS version 3.5.
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:
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
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;
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.
Remarks:
TinyButStrong integrate a technique to call methods or properties of objects that you've coded at the PHP side.
The following TBS features support the call to the methods of a class without created object.
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); |
Remark: Methods call using this technique must respect the function syntax expected by the feature (see the description of the corresponding feature).
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:
Remarks:
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') |
Remarks:
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'); |
Remark: Methods call using this technique must respect the function syntax expected by the feature (see the description of the corresponding feature).
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.
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
Element | Description |
---|---|
FieldName | The name of the Field. The dot (.) is a special character reserved for sub-names in TBS fields. It enables you to indicate a column name (see Blocks) or sub-values (see MergeField()). 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' Literal single quotes in the string must be escaped using two adjacent 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;strconv=[var.y]]
: [var.y] will not be merged and parameter "strconv" will
have an unvalid value.
[x;if [var.y]=1] : [var.y] will be correctly merged and the "if" condition will be correctly evaluated. |
Parameter | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
strconv=val |
Ennables you to modify the string conversion for this TBS field only. Note that the string conversion used by default for all TBS fields is the charset option. It is often corresponding to an Xml/Html charset but not necessary. You can specify several values using seperator '+'. Example : strconv=yes+js The values can be one of the following keywords:
Versioning:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
. (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. Syntax for value path: att=[+][tag1+tag2+tag3+...#]attribute
or att=. If you set att=. then TBS will assume that the TBS fields is already positioned inside the target attribute. 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 <div> placed before. [onshow.x;att=+div#class] moves into attribute 'class' of the first <div> placed after. [onshow.x;att=((div))#class] moves into attribute 'class' of the second embedding <div> placed before. [onshow.x;att=table+div#class] moves into attribute 'class' of the first <div> after the first <table> placed before. Notes:
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: <div
class="style1">[onshow.x;att=class;attadd]
in this example, if we have $x='style2' then we obtain <div class="style1 style2"> 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. Example: <div
class="old">[onshow.z;att=class;ope=msk:style*]
in this example, if we have $z='2' then we obtain <div class="style2"> 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). 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 or magnet=# |
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: (<a
href="[onshow.link;magnet=a]">click here</a>)
Result for $link='www.tbs.com': (<a href="www.tbs.com">click here</a>) Result for $link='': () By default, the magnet XML/HTML zone should be delimited by a pair of opening-closing tags (like <a></a>) which first tag is placed before the TBS fields. But this can be changed using parameter mtype (see below). Remark:the parameters if, then, else are processed before parameter magnet. Versioning:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mtype=val |
To be used with parameter magnet. Define the magnet type.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
enlarge |
Enlarge 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 <!-- [myfield;enlarge] here some comments --> yyy
or xxx <div> [myfield;enlarge=div] here
some comments </div> 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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
noerr |
Avoid some of the TBS Error messages for this TBS field. When such a message can be cancelled, it is mentioned in the message. After the error is cancelled, the value of the field becomes an empty string (''). See also the TBS option noerr which enables you to cancel any TBS error message. Option noerr is a bit different from the field's parameter noerr. Option noerr applies for any TBS error and will avoid the merge of a block or a field which has an error. While parameter noerr ensures the merge. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file=filename |
Replace the field with the contents of the file. Filename can be a string or an expression. Parameter file supports automatic embded fields [val] and [var]. 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. Examples: [onload;file=header.html]
[onload;file=[var.filename]] 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. Example: [onload;file=[var.insert;if [val]=1;then 'header.html';else '']]
You will found more details about this parameter in the chapter Subtemplates. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getpart=taglist |
To be used with parameter file
or script. Example: [onload;file=header.htm;getpart=(script)+(style)+body]
Versioning:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
store=taglist |
To be used with parameter file
or script. Parameter store is useful to use a sub-template as a component that will spread several contents in the main template. Example: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>The main template</title> [onshow.store.default] </head> <body> Here is a component : <div> [onload;file=component1.htm;getpart=body;store=(script)+(style)] </div> </body> </html> Versioning: Parameter store is supported since TBS version 3.8.0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
storename=name | To be used with
parameter store. Parameter storename changes the name of the
store. See parameter store.
Versioning: Parameter store is supported since TBS version 3.8.0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Parameter script supports automatic embded fields
[val] and [var]. 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.
See chapter 'Subtemplates' for more details about how to use this parameter in subtemplate mode. Versioning: Since TBS version 3.14.0 this feature is locked by default. You have to set the option scripts_allowed to true in order to unlock it. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 |
Replace the current value with the value of parameter then or else, depending on whether the condition is verified or not. Both parameters then and else are optional. A missing then or else means no replacement for its corresponding case. Supported operators are: (same as parameter when for blocks)
Both expr1 and expr2
must be string or numerical expressions. Parameter if supports automatic
embded fields [val] and
[var]. Example: [onshow.x;if [val]+-0;then 'OK';else 'FAIL']
The field will displayed OK only if « $x > 0 ». If the emmebed fields may contains single quotes, you need to use delimitors and to escape strings in the field's value and both expressions: [onshow.x;strconv=esc;if '[val]'='abc';then 'OK';else 'FAIL']
The field will displayed OK only if « $x == 'abc' ». The expressions may contain [var] fields and other TBS fields, but you have to make sure that they are merged before the containing field is merged. Otherwise the condition will always be considered as false. It is also possible to define several couples of if/then in the same field. Supported
since TBS version 3.0 [onshow.x;if [val]=0;then
'ZERO';if
[val]=10;then
'TEN';if
[val]=20;then
'TWENTY';else
[val]]
See parameters then and else for other examples. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
then val1 |
If the parameter if is defined and its condition is verified, then the data item is replaced with val1. Parameter then supports automatic embded fields [val] and [var]. 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']
[onshow.x;if [val]=1;then 'one';if [val]=2;then 'two';else 'more'] |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else val2 |
If the parameter if is defined and its condition is not verified, then the data item is replaced with val2. Parameter then supports automatic embded fields [val] and [var]. Example: [onshow.error_id;if [val]=0;then
'no error';else
'error found']
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onformat=fct_name |
Indicates the name of a user Php function that will be
executed just before the value is formated for the merge.
This allows typically to modify the text to display. The
onformat function does not replace the formating. String
conversion or parameter frm are applied just after the onformat function. The function fct_name must
have the following syntax:
Example: HTML: [onshow.x;onformat=f_to_utf8]
PHP:
function f_to_utf8($FieldName, &$CurrVal) { $CurrVal= utf8_encode($CurrVal); } See chapter 'Subtemplates'
for more details about how to use this arguments in
subtemplate mode. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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: 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 TBS option '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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 Interpretation of merged values:
It is recommended to use parameter frm with date-time value that use a non-ambiguous string representation, such as "yyyy-mm-dd hh:nn:ss". Most of PHP driver for Database System return date-time values and timestamp values is this format. Versioning:
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. 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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
combo=names |
Apply combo's parameters. A combo is a set of parameters that have been previously defined at the PHP side using method SetOption('prm_combo'). Any other explicit parameters in the TBS field will override parameters coming from the combo. You can apply several combo by separating names with coma (,). Combo are useful to make reusable set of parameters, or to shorten a TBS tag when parameter are too long for the template. See also method ReplaceField() in order to shorten fields in the template. Example: PHP:
$TBS->SetOption('prm_combo', 'add_date', array('att'=>'div#data-date', 'frm'=>'yyyy-mm-dd', 'magnet'=>'div', 'enlarge'=>'span')); HTML: [onshow.x;combo=add_date]
Versioning: parameter combo is supported since TBS version 3.11.0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
locale |
Deprecated since TBS version
3.4.0, and may be badly supported. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. |
When you want to use several parameters in the same TBS field, then
it can be interesting to understand in which order they are
processed.
TBS changes the value to be merged, without changing the original
value.
Order of processes:
Automatic fields enable you to automatically merge data when some events occur.
Automatic fields support subnames. They merges items stored in $TBS->VarRef. By default $TBS->VarRef is a reference on $GLOBAL. See property VarRef for more details.
Automatic fields can also merge TBS special information (see Special automatic fields), or data of the ObjectRef property (see Objet Oriented Programming).
An automatic field without subname will be merged with an empty string value ('').
There are three types of automatic fields:
Of course automatic fields support all fields' parameters.
Examples :
[onload.x] | Will be merged with the global variable $x when the LoadTemplate() method is called. |
[onshow.x] | Will be merged with the global variable $x when the Show() method is called. |
[onload;file=header.html] | Inserts a subtemplate when LoadTemplate() method is called. |
[b1.col1;if [val]=[var.x];then 'good'; else 'bad'] | The [var.x] field will be merged only when its parent [b1.col1] is merged. |
Automatic fields cannot merge a variable which is local to a function. You can add your local variable to $TBS->VarRef, or you can merge it using MergeField().
Note: You can force the merge of automatic fields using MergeField().
Some parameters can manage embedded TBS fields. That is those embedded fields will be automatically merged at the time the parameter is evaluated.
Inside parameters file, script, if, then, else, embedded automatic fields are : [var] and [val].
Inside parameters when, embedded automatic fields are : [var] and the fields of the same block.
Note that the special fields [val] and [var] won't be merged when placed inside other parameters.
Note that other ordinary embedded fields won't be merged when placed inside any other parameters. You have to ensure that such fields are merged before, otherwise the merged result could be unexpected. Most of the time such embedded fields are simply not merged.
Bad templating examples:
[onload;if [onload.x]=1;then
'yes';else 'no']
This example will always display 'no',
because the embedded field [onload.x]
will never be merged (only [val] and [var] could be merged here).
Corrects expressions are :
[onload;if [var.x]=1;then
'yes';else 'no']
[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)
You can limit the automatic fields usage by defining a prefix for allowed PHP variables. For details, see create a new TBS object.
TBS options onload and onshow enable you to cancel the processing of [onload] and [onshow] fields. Those options 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 onshow option is set to false. See method SetOptions() for more details about TBS options.
Versioning:
A Special automatic field is a TBS automatic field which has a
special name and can display special data provided by the template
engine.
The special names can work only with automatic
fields. That is [onload], [onshow] and [var].
The scpecial names always have a double dot before the key instead
of one.
Example: Date of the day : [onshow..now;frm='mm-dd-yyyy']
Key | Description | Example |
---|---|---|
now | Date and hour of the server. | [onshow..now;frm='mm-dd-yyyy'] |
version | The version of TinyButStrong. | [onshow..version] |
script_name | The name of the PHP file currently executing. | <form action="[onshow..script_name]"> |
template_name | The name of the last loaded
template file. It is the name given to the LoadTemplate() method. |
|
template_date | The creation date of the last loaded template file. | |
template_path | The directory of the last loaded
template file. It is the directory given to the LoadTemplate() method. |
|
tplvars.* | The value of an item set in the TplVars property. ('*' must be the key of an existing item in the array) |
[onshow..tplvars.title] |
cst.* | The value of a PHP constant. (* must be the name of an existing constant) |
[onshow..cst.PHP_VERSION] |
tbs_info | Information about TBS and installed plug-ins. | [onshow..tbs_info] |
error_msg | Display errors that have been avoid during the time when TBS option noerr is set to true. | [onshow..error_msg] |
php_info | Display the PhpInfo sight, the same as the PHP function phpinfo(). | [onshow..php_info] |
store.* | Display the contents aggregated in a store. | [onshow..store.default] |
Versioning:
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 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:
The dot (.) is a special character reserved for sub-names in TBS field. It cannot be used in a column's name.
The space character ( ) is supported in column names since TBS version 3.5.0.
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.
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>
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. |
|||||||||||||||||||||
parallel=configuration_id |
Merge a block with a parallel process for sub-blocks. This
can typically merges a table block in columns. Versioning: parameter parallel is supported since TBS version 3.9.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. The syntax is the same as headergrp. | |||||||||||||||||||||
splittergrp=colname | Indicates a splitter section that is displayed each time the value of column colname changes. The syntax is the same as 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. | |||||||||||||||||||||
firstingrp=colname | Indicates a
section which replaces the normal section each time the value
of column colname is the first
in its group. That is when the value is different from the
previous one. You can define several firstingrp, lastingrp, singleingrp sections but only the first relevant one will be displayed for the same record if they are several relevant. The syntax is the same as headergrp. Parameter firstingrp is supported since TBS 3.12. |
|||||||||||||||||||||
lastingrp=colname | Indicates a
section which replaces the normal section each time the value
of column colname is the last
in its group. That is when the value is different from the
next one. The syntax is the same as headergrp. Parameter lastingrp is supported since TBS 3.12. |
|||||||||||||||||||||
singleingrp=colname | Indicates a
section which replaces the normal section each time the value
of column colname single in
its group. That is when the value is different from the
previous and the next one. This parameter is useful when you
use both firstingrp and lastingrp and you also need to
specify when happen when both cases are met. The syntax is the same as headergrp. Parameter singleingrp is supported since TBS 3.12. |
|||||||||||||||||||||
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: (same as parameter if/then/else for fieds)
Both expr1 and expr2
must be string or numerical expressions. Parameter if supports automatic embded fields [var]. Example: <div> ... [onload;block=div;when
[var.x]+-0] ... </div>
The <div> block will be displayed only if « $x > 0 ». If the emmebed fields may contains single quotes, you need to use delimitor and to escape strings in both expressions: <div> ... [onload;block=div;when
'[var.x;strconv=esc]'='abc'] ... </div>
The <div> block will be displayed only if « $x == 'abc' ». 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. |
|||||||||||||||||||||
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. |
Different blocks having the same name will be regarded as sections of the same block.
Sections can be used to:
When you define several normal sections, they will be used alternatively for each record.
Example:
[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.
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 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 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] |
The parallel merge is supported since TBS version 3.9.0.
The parameter parallel enables you to merge a block with a parallel process for sub-blocks. This can typically merges a table block in columns.
First of all you have to define a block over one or several closed cells in the same row of a table. It can be at any row of the table, it makes no difference. Then add parameter "parallel=tbs:table" to this block. Then TBS will merge the cells as expected for this row, but also for all the same columns of other rows in the table. The configuration "parallel=tbs:table" tells TBS how is structured the <table> element in HTML, and then it can found other cells of the same columns. TBS can even process spanned cells if it is consistent with the asked merge.
By default, TinyButStrong supports the configuration named "tbs:table" for merging HTML tables. But you can define your own configurations.
Template:
Category | [b.date] |
Thin | [b.thin;block=td;parallel=tbs:table] |
Heavy | [b.heavy] |
Total | [b.total] |
PHP:
$data = array( array('date' => '2013-10-13', 'thin' => 156, 'heavy' => 128, 'total' => 284), array('date' => '2013-10-14', 'thin' => 233, 'heavy' => 25, 'total' => 284), array('date' => '2013-10-15', 'thin' => 110, 'heavy' => 412, 'total' => 130), array('date' => '2013-10-16', 'thin' => 258, 'heavy' => 522, 'total' => 258), ); $TBS->MergeBlock('b', $data);
Result:
Category | 2013-10-13 | 2013-10-14 | 2013-10-15 | 2013-10-16 |
Thin | 156 | 233 | 110 | 128 |
Heavy | 128 | 25 | 412 | 130 |
Total | 284 | 258 | 522 | 258 |
Remark: The parallel merge doesn't work with headergrp and serial mode.
$configuration = array( // Name of the parent entity. The process will be limited to this element and its childs. 'parent' => 'table', // Names of tags that must be simply ignored. Such start and ending tags are ignored but childs are not ignored. // For elements that must be completely ignored including childs, you just have to not mentioned it in the configuration. 'ignore' => array('!--', 'caption', 'thead', 'thbody', 'thfoot'), // Names of entities recognized as column's definitions, and their span attributes ('' for no span attribute). // Such entities must always be placed before the row entities. 'cols' => array(), // Names of entities recognized as rows. 'rows' => array('tr'), // Names of entities recognized as cells, and their span attibute ('' for no span attribute). 'cells' => array( 'td' => 'colspan', 'th' => 'colspan', ), ); // Save the new configuratin with its ID. $TBS->SetOption('parallel_conf', 'tbs:table', $configuration);
The serial display enables you to display several records inside a block. For this, you have to use a main block and secondary blocks.
Example:
|
||||
|
||||
|
In this example, main blocks are the blue lines of the table, the secondary blocks are the pink cells.
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:
|
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:
|
||||
|
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.
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 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:
Example:
Name:
[body.name;block=tr;sub1=spokenlg]
|
Corresponding PHP code:
$data = array( array('name'=>'Peter', 'spokenlg'=>array( 'US', 'FR' ) ), array('name'=>'Paul', 'spokenlg'=>array( 'US' ) ), array('name'=>'Jack', 'spokenlg'=>array( 'FR', 'ES', 'IT') ), ); $TBS->MergeBlock('body', $data);
Result of the merge:
Name:
Peter
|
|||
Name:
Paul
|
|||
Name: Jack
|
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)]
|
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:
Group :
[body.$;block=tr;sub1]
|
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 parameter $query given to the MergeBlock() method must be a string and has to contain marks such as %p1%, %p2%, %p3%, ... in order to welcome the values of the parameters p1, p2, p3,...
Note that you can also use a dynamic query with a PHP Array using a string that refers to a PHP Array stored in a global variable. See Php data sources.
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
[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%')");
Or using an Array:
global $data_town; // the coutry code is the main key of the array $TBS->MergeBlock('blk', 'array', 'data_town[%p1%]');
Result of the merge:
Country: France
Paris | france |
Toulouse | france |
Country: USA
Washington | us |
Boston | us |
Dynamic queries enable you to easily build a system of a main-block with subblocks. Here is how you can do it:
Example:
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%)';
Or using an Array:
$TBS->MergeBlock('main', $data_county); global $data_town; // the coutry code is the main key of the array $TBS->MergeBlock('blk', 'array', 'data_town[%p1%]');
Result of the merge:
Country:
France
|
||
Country:
Germany
|
||
Country: Spain
|
Remarks:
Automatic blocks enable you to automatically merge conditional blocks when some events occur.
There are two types of automatic blocks:
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 can 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 subname.
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.
There are two ways to insert subtemplates in your main template.
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 '']]
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 <body> part (or another part). This can be done by adding parameter getpart to parameter file in the TBS field of the main template. This technique enables you to work WYSIWYG with your subtemplates.
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.
In the Subtemplate mode, 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.
Versioning: since TBS version 3.8.3, the PHP direct outputs (such as those done with the command echo) are no longer diverted from the subtemplate to the main template.
Example with parameter script:
HTML: |
[onload.file;script=specialbox.php;subtpl] |
---|---|
PHP script: |
<?php // script specialbox.php $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. |
TinyButStrong offers several tools for conditional display for both fields and blocks.
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. |
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.
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.
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.
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. |
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.
Extended methods are custom methods that you can add to a TinyButStrong instance. This can be usefull for a plug-in for example.
Versioning: Extended methods are supported since TBS version 3.8. The feature needs PHP 5.0 or higher.
Examples:
If you define:
$TBS->ExtendedMethods['newMethod1'] = array(&$myObject,
'myMethod');
then if you call:
$TBS->newMethod1($x);
it whill run :
$myObject->myMethod($x);
If you define:
$TBS->ExtendedMethods['newMethod2'] = 'myFunction';
then if you call:
$TBS->newMethod($x);
it whill run :
myFunction($x);
A block alias is a special name for a block definition, which will
be replaced with another list of tags or which will call a custom
function to find the block bounds.
Block alias really empower the way of defining blocks. It is useful
for plug-ins or when you want to simplify the understanding of the
template coder.
Versioning: Block alias are supported since TBS version 3.8.
Examples:
$TBS->SetOption('block_alias', 'row', 'tr'); // the alias replace one tag $TBS->SetOption('block_alias', 'dblrow', 'tr+tr'); // the alias replace several tags $TBS->SetOption('block_alias', 'my_alias', array($myObj, 'findBounds') ); // the alias call a custom function to find the bounds
Use in the template :
[blk1;block=row] or [blk1;block=row+row] or even [blk1;block=th+row] [blk2;block=dblrow] [blk3;block=my_alias]
Example :
class clsTest { /** * Function findBound() will be call two times for finding the bounds of the block. Once with $Forward=true, and once with $Forward=false. * It is supposed to return the position of the inner bounds of the block. * It can return false if an error occurs of if the template source is inconsistent for finding the block at the given position. * * @param string $Tag The name of the block alias * @param string $Txt The source of the template * @param integer $Pos The position of the TBS field in $Txt * @param boolean $Forward The direction of the search * @param mixed $LevelStop Encapsulation level in a block of the same type. Ignore this in your code if your block type does not support self-encapsulation. * @return integer */ function findBound($Tag, $Txt, $Pos, $Forward, $LevelStop) { if ($Forward) { return strpos($Txt, '}', $Pos); } else { return strrpos(substr($Txt, 0, $Pos+1), '{'); } } }
Versioning: Data Reader plug-ins are supported since TBS version 1.8.
When you use $TBS->MergeBlock($BlockName, $Source, $Query), TBS is first examining $Source to see if it supported as a data source.
A Data Reader plug-in enables TBS to to recognize new data sources.
You can found several examples of Data Reader plug-in at the TinyButStrong web site.
Synopsis:
function tbsdb_XXX_open(&$Source, &$Query)
function tbsdb_XXX_fetch(&$Rs [,$RecNum])
function tbsdb_XXX_close(&$Rs)
TBS will automatically use this Data Reader plug-in for $TBS->MergeBlock($BlockName, $Source, $Query) when:
Example with a direct object:
class MyCustomClass { function tbsdb_open(&$Source, &$Query) {...} function tbsdb_fetch(&$Rs ,$RecNum) {...} function tbsdb_close(&$Rs) {...} } $Source = new MyCustomClass(); $TBS->MergeBlock($BlockName, $Source, $Query);
When the MergeBlock process meet of value for $Source which is an object, and have at least 3 methods namedtbsdb_open(), tbsdb_fetch() and tbsdb_close(), then it assumes that the object is a Data Reader plug-in. 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.
Example with an objet saved in ObjectRef:
class MyCustomClass { function XXX_open(&$Source, &$Query) {...} function XXX_fetch(&$Rs ,$RecNum) {...} function XXX_close(&$Rs) {...} function YYY_open(&$Source, &$Query) {...} function YYY_fetch(&$Rs ,$RecNum) {...} function YYY_close(&$Rs) {...} } $TBS->ObjectRef = new MyCustomClass(); ... $TBS->MergeBlock($BlockName, '~XXX', $Query);When the MergeBlock process meet a value for $Source which is a string beginning with '~' then it assumes that property $TBS->ObjectRef is a Data Reader plug-in based on an object (see OOP). The object must have the same requirements as a Data Reader plug-in based on objet described above, but the names of the methods can be different.
Versioning: plug-ins are supported since TBS version 3.0.
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).
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 ... }
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:
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.
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(...) {...} ...
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.
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) |
• | BeforeMergeBlock | Executed when bounds of a block are founded. Can cancel TBS basic process. |
• | OnMergeSection | Executed when a section is merged, and before it is added to other sections. |
• | OnMergeGroup | Executed before a header, a footer or a splitter section is merged. (supported since TBS 3.3.0) |
• | AfterMergeBlock | Executed just before a merged block is inserted into the template. |
• | OnSpecialVar | Executed when a non native Special Var Field (like [onshow..now]) is met. |
• | OnMergeField | Executed on each field met when using the MergeField() method. |
Parameter | Summary |
---|---|
strconv |
Char conversion Mode for the field's value. |
htmlconv | Deprecated, alias of strconv. |
. (dot) | If the value is empty, then display an unbreakable space. |
ifempty | If the value is empty, then display another value. |
att | Move the field into the attribute of an XML/HTML tag. |
attadd | Use with att. Indicate that the merged value must be added instead of be replacing the attribute's value. |
atttrue | Use with att. Indicate that the target attribute must be managed as a boolean attribute. |
magnet | If the value is empty, then delete surrounding element. |
mtype | Use with magnet. |
if | If the condition is verified, then change the value. |
then | Use with if. |
else | Use with if. |
onformat | Executes a Php user function to modify the field merging. |
frm | Apply a date-time or a numeric format. |
combo | Apply a set of predefined parameters. |
tplfrms | Use with onload fields only. Define template formats. |
tplvars | Use with onload fields only. Define template variables. |
protect | Protection mode for characters '['. |
enlarge | Enlarges the field's bounds up to the Commentary tag that surround it. |
comm | Deprecated, alias of enlarge. |
noerr | Avoid some TBS error messages. |
file | Includes the contents of the file. |
script | Executes the Php script. |
getpart | Use with file or script. Insert only a part of the subtemplate. |
getbody | Deprecated, alias of getpart. |
store | Use with file or script. Store a part of the subtemplate in order to display it elsewhere. |
storename | Use with store. Change the name of the store. |
rename | Use with file or script. Rename TBS block and fields in a subtemplate. |
subtpl | Use with script or onformat. Turns the TBS instance into subtemplate mode. |
Parameter | Summary |
---|---|
block | Defines the block's bounds. |
nodata | Indicates the section that is displayed when there is no data in the data source. |
bmagnet | If there is no data, then delete the surrounding element. |
headergrp | Indicates a header section that is displayed when the value of a column changes. |
footergrp | Indicates a footer section that is displayed when the value of a column changes. |
splittergrp | Indicates a splitter section that is displayed when the value of a column changes. |
parentgrp | Indicates a parent section that is displayed when the value of a column changes. |
firstingrp | Indicates a section that replaces the normal section when the value of a column changes. |
lastingrp | Indicates a section that replaces the normal section when the value of a column changes. |
singleingrp | Indicates a section that replaces the normal section when the value of a column changes. |
parallel | Indicates a configuration for merging data in columns or with any custom parallel method. |
serial | Indicates a section that contains a series of several records. |
p1 | Sends a parameter to the dynamic query for the data source. |
sub1 | Define the column containing the data for an automatic subblock. |
ondata | Executes a Php user function to modify the record when it has just been taken from the data source. |
when | Use with onload or onshow. Displays the section when the condition is verified. |
default | Use with onload or onshow. Displays the section when no section is displayed. |
several | Use with when. Indicate that several blocks of the group can be displayed. |
Name | Summary |
---|---|
val | The keyword [val] can be used in field's parameters to represent the field's value. |
# | Virtual column name for a block. It displays the record's number. |
$ | Virtual column name for a block. It displays the record's key if the data source is a Php Array. |
onload | Automatic field or block, merged when the template is loaded. |
onshow | Automatic field or block, merged when the template is shown. |
var | Embedded automatic field. |