tbs manual

34
13/02/12 TBS Manual 1/34 www.tin\butstrong.com/manual.php#php_mergeblock What is it for? Why use it? Examples Downloads Manual Plug-ins Other tools News Support Forum Testimonials Your sites Français Site: www.tinybutstrong.com A uthors: skrol29 , P irjo Date: 2011-10-26 *.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.* TinyButStrong Documentation version 3.8 *.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.*.A.* Template Engine for Pro and Beginners for PHP 5 Table of Contents: Subject Description Introduction Basic principles Installation Mini examples PHP side To begin create a new TBS object for working with templates method LoadTemplate() load the contents of a template from a file method MergeBlock() merge a part of the template with a data source method Show() automatic processing and display of the result Advanced method GetBlockSource() returns the source of the definition of a block method MergeField() merge a specific field with a value method PlugIn() execute a plug-in's action property Assigned prepares information for a subsequent merging property NoErr avoid error messages property Render to alter the merge ending option property Source returns the current contents of the result property TplVars returns template variables Object Oriented Programming (OOP) to make TBS OOP friendly Template side TBS fields Definition and syntax Parameters Order of processing parameters Automatic fields Special Automatic fields TBS blocks Definition and syntaxes Parameters Sections of block Automatic blocks Serial display (in columns) Subblocks Automatic subblocks Subblocks with dynamic queries Miscellaneous Subtemplates Conditional display overview Coding plug-ins Database Plug-ins Other plug-ins Summary TBS Field's parameters TBS Block's parameters Names of Special Fields and Blocks

Upload: iur-olirg

Post on 10-Oct-2014

159 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TBS Manual

13/02/12 TBS Manual

1/34www.tinybutstrong.com/manual.php#php_mergeblock

What is it for? Why use it? Examples Downloads Manual Plug-ins Other tools News Support Forum Testimonials Your sites

Français

Site: www.tinybuts trong.com

A uthors : skrol29 , P irjo

Date: 2011-10-26

* . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . *

TinyButStrong Documentation

vers ion 3 .8* . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . * . ^ . *

Template Engine for Pro and Beginnersfor PHP 5

Table of Contents:

Subject Description

• Introduction

Basic principles

Installation

Mini examples

• PHP side

• To begin

create a new TBS object for working with templates

method LoadTemplate() load the contents of a template from a file

method MergeBlock() merge a part of the template with a data source

method Show() automatic processing and display of the result

• Advanced

method GetBlockSource() returns the source of the definition of a block

method MergeField() merge a specific field with a value

method PlugIn() execute a plug-in's action

property Assigned prepares information for a subsequent merging

property NoErr avoid error messages

property Render to alter the merge ending option

property Source returns the current contents of the result

property TplVars returns template variables

Object Oriented Programming (OOP) to make TBS OOP friendly

• Template side

• TBS fields

Definition and syntax

Parameters

Order of processing parameters

Automatic fields

Special Automatic fields

• TBS blocks

Definition and syntaxes

Parameters

Sections of block

Automatic blocks

Serial display (in columns)

Subblocks

Automatic subblocks

Subblocks with dynamic queries

• Miscellaneous

Subtemplates

Conditional display overview

• Coding plug-ins

Database Plug-ins

Other plug-ins

• Summary

TBS Field's parameters

TBS Block's parameters

Names of Special Fields and Blocks

Page 2: TBS Manual

13/02/12 TBS Manual

2/34www.tinybutstrong.com/manual.php#php_mergeblock

Introduction:

TinyButStrong (TBS) is a PHP class useful to develop an application in a clean way, separating PHP scripts andXML/HTML/Text files. With TBS, the files are generated dynamically by merging a template with data. It is called a TemplateEngine.

The name TBS comes from the fact that this tool contains only 8 functions and yet, it is very powerful. It allows you tomerge 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 orFrontPage). But if you are used to designing your templates with a text editor, it is nice as well. TBS also enables you tocreate JavaScript dynamically.

As the name of it tells, TBS is easy to use, strong and fast. It is completely °~° freeware °~°.

Basic principles:

On the HTML side (or other file type):You design a page which does not necessarily contain any PHP scripts, nor any programming. In this page you place TBStags 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 todefine 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 ofthe merge.

Installation:

1. Copy the file tbs_class.php in a directory of your Web site.2. At the beginning of your PHP program, add the lines:

i n c l u d e _ o n c e ( ' t b s _ c l a s s . p h p ' ) ;

$ T B S = & n e w c l s T i n y B u t S t r o n g ; 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 ofthe TBS file name.

Explanations and technical details:TinyButStrong is a library written in PHP, it's a component to be referenced in your own PHP programs. In technical terms,TinyButStrong is a PHP 'class' ; the name of this class is clsTinyButStrong.The variable $TBS that you add at the beginning of your PHP program enables you to execute the merge of your templatefrom your PHP application. In technical terms, the variable $TBS is an 'instance' of the clsTinyButStrong class.

Mini examples:

Example 1:

Html Template Php Program Result

<html> <body> [onshow.message] </body></html>

< ?

i n c l u d e _ o n c e ( ' t b s _ c l a s s . p h p ' ) ;$ T B S = & n e w c l s T i n y B u t S t r o n g ;

$ T B S - > L o a d T e m p l a t e ( ' t e m p l a t e . h t m ' ) ;

$ m e s s a g e = ' H e l l o ' ;$ T B S - > S h o w ( ) ;

? >

<html> <body> Hello </body></html>

Example 2:

Html Template Php Program Result

<table> <tr><td>[blk.val;block=tr]</td></tr></table>

< ?

i n c l u d e _ o n c e ( ' t b s _ c l a s s . p h p ' ) ;$ T B S = & n e w c l s T i n y B u t S t r o n g ;

$ T B S - > L o a d T e m p l a t e ( ' t e m p l a t e . h t m ' ) ;

$ l i s t = a r r a y ( ' X ' , ' Y ' , ' Z ' ) ;$ T B S - > M e r g e B l o c k ( ' b l k ' , $ l i s t ) ; $ T B S - > S h o w ( ) ;

? >

<table> <tr><td>X</td></tr> <tr><td>Y</td></tr> <tr><td>Z</td></tr></table>

Page 3: TBS Manual

13/02/12 TBS Manual

3/34www.tinybutstrong.com/manual.php#php_mergeblock

PHP side:

The merging of a template is done in a PHP program using an object variable declared as a clsTinyButStrong class.Example of statement: $ T B S = n e w c l s T i n y B u t S t r o n g ;

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:

i n c l u d e _ o n c e ( ' t b s _ c l a s s . p h p ' ) ;$ T B S = & n e w c l s T i n y B u t S t r o n g ;

$ T B S - > L o a d T e m p l a t e ( ' t e m p l a t e . h t m ' ) ;$ T B S - > M e r g e B l o c k ( ' c t r y ' , ' m y s q l ' , ' S E L E C T * F R O M t _ c o u n t r y ' ) ;$ T B S - > S h o w ( ) ;

Here is the description of the TinyButStrong object:

create a new TBS object:

A TBS object is created as a new instance of the clsTinyButStrong class. A TBS object enables you to work with oneor several templates using the object's methods and properties.

Syntax to create a new TBS object: $ T B S = n e w c l s T i n y B u t S t r o n g ( { s t r i n g T a g D e l i m { , s t r i n g V a r P r e f i x { ,

s t r i n g F c t P r e f i x } } } )

Argument Description

TagDelim Define the couple of delimiters for TBS tags recognized in templates. The default value is '' (emptystring) which means the default TBS delimiters. That is '[' and ']'.Example: if you want to have the delimiters to be {{ and }} for TBS fields, then set TagDelim to thevalue '{{,}}'. Thus TBS fields will be like {{var.x}} instead of [var.x]. It's recommended to let the default TBS delimiters, while changing them is working well. Default TBSdelimiters are [ and ] because those characters are usable quite everywhere in XML/HTMLdocuments, and they are located faster than delimiters { / } or ( / ) since they are rarer, especially inHTML.

VarPrefix Limit the usage of automatic fields ([onload] [onshow] and [var]) in templates. TBS will display onlyglobal PHP variables prefixed with VarPrefix. Other variables will produce an error message. Thedefault for VarPrefix value is '' (empty string) which means no limitation.

FctPrefix Limit the usage of custom PHP functions (relative to parameters onformat and ondata) in templates.TBS will call only PHP function prefixed with FctPrefix. Other functions will produce an error message.The default value is '' (empty string) which means no limitation.This argument is supported since TBS version 3.6.0.

Examples:

$ T B S 1 = n e w c l s T i n y B u t S t r o n g ; / / d e f a u l t b e h a v i o r$ T B S 2 = n e w c l s T i n y B u t S t r o n g ( ' { { , } } ' ) ; / / T B S t a g s w i l l b e l i k e { { v a r . x } } i n s t e a d o f [ v a r . x ]$ T B S 3 = n e w c l s T i n y B u t S t r o n g ( ' ' , ' t b s _ v a r _ ' ) ; / / T B S w i l l d i s p l a y o n l y P H P g l o b a l v a r i a b l e s

b e g i n n i n g w i t h ' t b s _ v a r _ '$ T B S 4 = n e w c l s T i n y B u t S t r o n g ( ' ' , ' ' , ' t b s _ f c t _ ' ) ; / / T B S w i l l c a l l o n l y P H P f u n c t i o n b e g i n n i n g w i t h' t b s _ f c t _ '

method LoadTemplate():

Loads a template for the merging process.The complete contents of the file is immediately stored in the Source property of the TBS object, then [onload] fieldsand 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: $ T B S - > L o a d T e m p l a t e ( s t r i n g F i l e { , s t r i n g C h a r s e t } )

Argument Description

File Local or absolute path of the file to load.This value can be null or '' (empty string) for special actions. See below for more details.

Charset Optional. Indicates the character encoding (charset) to use for conversion of special characters whendata will be merged. It should be the same as the charset of the template. The default value is ''(empty string) which is equivalent to 'ISO-8859-1' (Latin 1).

If your template uses a special charset, then indicate the Html value for this charset.In a Html page, the charset is placed at the beginning of the file, in the attribute 'content' of a<Meta> tag. The charsets supported by TBS are the charsets supported by the PHP functionhtmlentities(). For example: 'BIG5' (Chinese) or 'EUCJP' (Japanese).

Page 4: TBS Manual

13/02/12 TBS Manual

4/34www.tinybutstrong.com/manual.php#php_mergeblock

See below for more possibilities.

Scope of the file path:If the file is nout found then its' also searched into the directory of the last loaded template, or the last loadedsubtemplate. Since TBS version 3.3.0, the file also searched into the include_path.

No character conversion: If you use value False as the argument Charset, data will to not be converted when merged into the model.Note that parameters htmlconv can be use to define the conversion of special characters for one TBS field only.

User function: If your charset is not yet supported by PHP, you can indicate a user function that will perform the conversion ofspecial characters. For this, use the argument Charset with the syntax '=myfunction'.Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).Since TBS version 3.3.0, such a custom function should have a second argument for line break conversion.Since TBS version 3.5.0, argument Charset can also be an array containing an object and a method. Example:array(&$obj, 'mymethod'). Here is an example which gives the expected syntaxe:

f u n c t i o n f _ S t r T o X m l ( $ T x t s t r i n g , $ C o n v B r b o o l e a n ) {

/ / C o n v e r t a s t r i n g i n t o a n X M L t e x t . $ x = h t m l s p e c i a l c h a r s ( u t f 8 _ e n c o d e ( $ T x t ) ) ;

i f ( $ C o n v B r ) { $ x = n l 2 b r ( $ x ) ; / / C o n v e r t a n y t y p e o f l i n e b r e a k $ x = s t r _ r e p l a c e ( ' < b r / > ' , ' < t e x t : l i n e - b r e a k / > ' , $ x ) ; r e t u r n $ x ; }

Adding the file at the end of the current template:You can use the keyword '+' for the argument Charset to have the file defined by File added to the end of thecurrent template. The current charset will not be modified.

Special actions using argument File:Since TBS version 3.4.0.If File is null, then all default actions (Plug-ins, [onload] tags, and Charset) are applied without loading any file. If File is '' (empty string), then only the charset is modified, without doing any other action.In both cases, if Charset is '+', then it will be ignored and the current charset will not be modified. Example:

$ T B S - > S o u r c e = $ t e m p l a t e ; / / l o a d t h e t e m p l a t e f r o m a s t r i n g $ T B S - > L o a d T e m p l a t e ( n u l l , ' B I G 5 ' ) ; / / r u n p l u g - i n s i f a n y , a n d m e r g e s [ o n l o a d ] t a g s i f a n y. . .$ T B S - > L o a d T e m p l a t e ( ' ' , f a l s e ) ; / / t u r n t h e c h a r s e t t o n o - c h a r s e t

method MergeBlock():

Merges one or several TBS blocks with records coming from a data source.by default, this method returns the number of merged records (more exactly, it is the number of the last record), butit can also return the full merged record set (see argument BlockName).

TinyButStrong supports several data source types in native:Php data: an array, a string, a number.Databases: MySQL ; PostgreSQL ; SQLite.You can also add a new one: 'database plug-ins'.

Syntax: i n t $ T B S - > M e r g e B l o c k ( s t r i n g B l o c k N a m e , m i x e d S o u r c e { , s t r i n g Q u e r y } { , m i x e d Q r y P r m s } )

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. Ifyou 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.The table below shows the possible values according to the data source type.

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 inaccount.Versioning: the argument QryPrms is supported since TBS version 3.7.0.

Link between the block and the records:

Page 5: TBS Manual

13/02/12 TBS Manual

5/34www.tinybutstrong.com/manual.php#php_mergeblock

The MergeBlock() method searches in your template for the specified TBS block name. Then, the block isrepeated 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 iscomposed of the block's name followed by a dot and a column's or a key's name in the record set. A linked fieldmust be inside the block.

Example:

Block's name: block1Columns returned by the query: field1,field2,field3Linked TBS Fields: [block1.field1], [block1.field2], [block1.field3]

If no block's definition is found in the template, then the MergeBlock() method will merge the first record with alllinked fields found in the template.

You can also define more advanced blocks. For more information, refer to chapter TBS Blocks.

Merging several blocks with the same data:

You can merge several blocks with the same data by indicating their names separated by commas in theBlockName parameter. In this case, the query is opened only one time, and records are buffered to feed blocks.Example: $ T B S - > M e r g e B l o c k ( ' b l o c k 1 , b l o c k 2 , b l o c k 3 ' , ' m y s q l ' , ' S E L E C T * F R O M M y T a b l e ' ) ;

You cannot merge several blocks having the same names because they are considered by TBS has a one andonly block composed of several sections. Nevertheless, you can use a tip to get a similar behavior. If you useparameter p1 without value in the block definition, that does forces TBS to consider the section as a new blockbreak, like it does for subblocks.Example:

Id Name

[b.id;block=tr;p1] [b.name]

Id Name

[b.id;block=tr;p1] [b.name]

$ T B S - > M e r g e B l o c k ( ' b ' , ' m y s q l ' , ' S E L E C T * F R O M M y T a b l e ' ) ;

Versioning: this tip is available since TBS version 3.4.

Returning the full merged record set:

In some cases, it may be useful for you to retrieve the full record set after the merge. For that, you simply haveto ad the keyword '*' in the list of block's names. Use this feature with care, because it save the merged data inthe memory which can take resources.Example: $data = $ T B S - > M e r g e B l o c k ( ' b l o c k 1 , * ' , ' m y s q l ' , ' S E L E C T * F R O M M a T a b l e ' ) ;

Counting the records:

To display the number of the record in the template, use a TBS Field linked to the virtual column '#'. If you putthis field outside the block, it will display the total number of records.Example: [block1.#]

The virtual column '$' will display the key of the current record if the data source is a Php array.Example: [block1.$]

Resource and Request arguments according to the data source type:

Data Source Type Source Query

Assigned (*) The keyword 'assigned' or omitted -

Text (*) The keyword 'text' A text

Number (*) The keyword 'num' A number or a special array (see below)

Clear (*) The keyword 'clear' -

Conditional (*) The keyword 'cond' -

PHP Array (*) A Php array -

The keyword 'array' A Php Array

The keyword 'array' A string that represents an array contained or nestedin a PHP global variable (see below)

PHP ArrayObject A PHP object. Supported since TBSversion 3.5.0.

-

PHP Iterator

PHP IteratorAggregate

PDO A PDO object. Supported since TBSversion 3.7.0.

An SQL statement. Optional argument QryPrms canbe 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 canbe used like with $db->execute($sql, $prms).

MySQLi A MySQLi object. Supported sinceTBS version 3.7.0.

An SQL statement

Page 6: TBS Manual

13/02/12 TBS Manual

6/34www.tinybutstrong.com/manual.php#php_mergeblock

MySQL A MySql connection identifier or thekeyword 'mysql'

An SQL statement

A MySql result identifier -

PostgreSQL A PostgreSql connection identifier An SQL statement

A PostgreSql result identifier -

SQLite An SQLite connection identifier An SQLite statement

An SQLite result identifier -

custom A keyword, an object or a resourceidentifier not mentioned in this table.See the chapter 'database plug-ins'.

An SQL statement or something else.

(*) See explanations in the chapter below.

Php data sources:

Assigned

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 : $ T B S - > M e r g e B l o c k ( ' b 1 ' ) ;

Versioning: the keyword 'assigned' is supported since TBS version 3.5.

Text

The argument Source has to be equal to 'text'.The whole block is replaced by the text (it must be a string) given as the Query argument. No linked Fieldsare processed except '#' which returns 1, or 0 if Query is an empty string.Example: $ T B S - > M e r g e B l o c k ( ' b 1 ' , ' t e x t ' , ' H e l l o , h o w a r e y o u ? ' ) ;

Number

The argument Source has to be equal to 'num'.The argument Query can be either a number or an array.

arg Query Returned Record SetNumber: 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:

$ T B S - > M e r g e B l o c k ( ' b 1 ' , ' n u m ' , 1 2 ) ;

$ T B S - > M e r g e B l o c k ( ' b 2 ' , ' n u m ' , a r r a y ( ' m i n ' = > 2 0 , ' m a x ' = > 3 0 ) ) ;$ T B S - > M e r g e B l o c k ( ' b 3 ' , ' n u m ' , a r r a y ( ' m i n ' = > 1 0 , ' m a x ' = > 2 0 , ' s t e p ' = > 2 ) ) ;

Clear

The argument Source has to be the keyword 'clear'.All blocks and sections are deleted. It is the same thing as merging with an empty array.Example: $ T B S - > M e r g e B l o c k ( ' b 1 ' , ' c l e a r ' ) ;

Conditional

The argument Source has to be the keyword'cond'.The block is merged like it was a conditional blocks onload and onshow. The block is not merged with data,and so it must have no linked TBS field. Each block section needs a parameter when or a parameter default.See conditional blocks for more details.Example: $ T B S - > M e r g e B l o c k ( ' b z ' , ' c o n d ' ) ;

Array

The argument Source has to be a PHP Array or the keyword 'array'. If you use the keyword 'array', then theargument Query has to be a Php Array or a string that represents an array contained or nested in a globalvariable.

String syntax: 'globvar[item1][item2]...'

'globvar' is the name of a global variable $globvar which must be an array.'item1' and 'item2' are the keys of an item or a subitem of $globvar.Example:

$ T B S - > M e r g e B l o c k ( ' b l o c k 1 ' , ' a r r a y ' , ' d a y s [ m o n ] ' ) ;

This will merge 'block1' with the value $day['mon'] assuming it is an array.

It is possible to represent variable's name without items.Example:

$ T B S - > M e r g e B l o c k ( ' b l o c k 1 ' , ' a r r a y ' , ' d a y s ' ) ;

There are two advantages in using a string to represent the array:-> Items will be read directly in the Array (assigned by reference) instead of reading a copy of the items. Thiscan improve the performance.-> You can use dynamic queries.

Page 7: TBS Manual

13/02/12 TBS Manual

7/34www.tinybutstrong.com/manual.php#php_mergeblock

Displaying the key of current record:You can use the virtual column '$' which will display the key of the current record. This can be usefulespecially for subblocks with dynamic queries. Example: [block1.$]

Structure of supported arrays: Items of the specified Array can be of two kinds: simple values with associated keys (case 1), or array valuesfor 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.

method Show():

Terminates the merge.

Syntax: $ T B S - > S h o w ( { i n t R e n d e r } )

The Show() method performs the following actions:- Merge [var] fields (for compatibility with version prior to 3.2.0),- Merge [onshow] fields and blocks,- Display the result (this action can be cancelled by Render property/argument),- End the script (this action can be cancelled by Render property/argument).

The Render property/argument allows to adjust the behavior of the Show() method. See the Render property formore information.

method GetBlockSource():

Returns the source of a TBS Block from the template.If no block is found, the method returns F a l s e .

Syntax: s t r i n g $ T B S - > G e t B l o c k S o u r c e ( s t r i n g B l o c k N a m e { , b o o l e a n A s A r r a y } { , b o o l e a n D e f T a g s } { , m i x

R e p l a c e W i t h } )

Argument Description

BlockName The name of the block to search for.

AsArray Optional. The default value is F a l s e . If this parameter is T r u e 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 issaved as an item. First item is index 1.

DefTags Optional. The default value is T r u e . 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 argumentDefTags to False. If the block is defined with a simplified syntax then the definition tags will not bedeleted 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 inthe template. You can use ReplaceWith = '' (empty string) in order to delete the block source fromthe template.Versioning: this argument is supported since TBS version 3.05.

This method enables you to get the source of a block in order to manually handle the merging.After that, if you need to replace the block with text, you can use the MergeBlock() method with the 'text' parameter.Versioning: Since TBS 3.05 if AsArray is False then the method returns block with all its sections ; before TBS 3.05 itreturn only the first section. Since TBS 3.05 if AsArray is True and the block is not found then the method returnsFalse ; before TBS 3.05 it return an empty Array.

method MergeField():

Page 8: TBS Manual

13/02/12 TBS Manual

8/34www.tinybutstrong.com/manual.php#php_mergeblock

Replaces one or several TBS Fields with a fixed value or by calling a user function.Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).Each TBS fields having the specified base name will be merged.It is also possible to merge the special [onload], [onshow] and [var] (see below).

Syntax: $ T B S - > M e r g e F i e l d ( s t r i n g B a s e N a m e , m i x e d X { , b o o l e a n F u n c t i o n M o d e } { , a r r a y D e f a u l t P r m } )

Argument Description

BaseName Base name of the TBS Fields. For example 'account'.

X The value to display (or a string that represent the name of a user function if the argumentFunctionMode is set to true).

FunctionMode Indicates that the value to display is calculated by a user function. The default value is false. If thisargument is set to true, then X must be a text string giving the name of the user function. Thisfunction 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 anassociative PHP array. If a parameter is defined in both argument DefaultPrm and in the field, thenthe parameter of the field will be taken in account.This argument is supported since TBS version 3.5.0.

Merging with a value:

X can be numeric, string, an array or an object. For an array or an object, names of TBS Fields must have suffixes likeautomatic fields ([onload] and [onshow]).

Example:

$ T B S - > M e r g e F i e l d ( ' a c c o u n t ' , a r r a y ( ' i d ' = > 5 5 , ' n a m e ' = > ' B o b ' ) ) ;In this example, the fields [account.id] and [account.name] will be merged.

Merging with a user function:

TBS calls this function for each field found in the template.This function must have the following syntax:

f u n c t i o n f c t _ u s e r ( $ S u b n a m e [ , $ P r m L s t ] ) { . . . }

When the function is called, its argument $Subname has for value the suffix of the field's name (example: for a fieldnamed 'ml.title', $Subname will have the value 'title'). And the optional argument $PrmLst contains an associativearray with the field's parameters. The function must return the value to be merged.

Example:

$ T B S - > M e r g e F i e l d ( ' m l ' , ' m _ m u l t i l a n g u a g e ' , t r u e ) ;. . .

f u n c t i o n m _ m u l t i l a n g u a g e ( $ S u b n a m e ) { g l o b a l $ l a n g _ i d ;

$ r s = m y s q l _ q u e r y ( " S E L E C T t e x t _ $ l a n g _ i d A S t x t F R O M t _ l a n g u a g e W H E R E k e y = ' $ S u b n a m e " ) ; $ r e c = m y s q l _ f e t c h _ a r r a y ( $ r s ) ;

r e t u r n $ r e c [ ' t x t ' ] ;}In this example, a field such as [ml.title] will be merged with the value returned by m_multilanguage('title').

Merge automatic fields and blocks:

You can use the method MergeField() in order to force the merge of the automatic fields and blocks ([onload] and[onshow]). But in this case, only the first argument should be indicated.Example: $ T B S - > M e r g e F i e l d ( ' v a r ' ) ;

Versioning: the merge of special fields is supported since TBS version 3.0. It replaces the old method MergeSpecial()which is not supported anymore.

Method PlugIn():

Enables you to call a TBS plug-in's command, or to install a TBS plug-in.

Syntax: m i x e d $ T B S - > P l u g I n ( m i x e d a r g 1 , m i x e d a r g 2 , . . . )

Remind: in order to have your TBS plug-in working, its PHP script must be included in your application before.Example: i n c l u d e _ o n c e ( ' t b s _ p l u g i n _ x x x . p h p ' ) ;

And aslo, every TBS plug-in should have a key as explained at Plug-ins.

Calling a plug-in's command:Use the plug-in's key as the main argument. Next arguments are for the called plug-in's purpose. Example:

$ T B S - > P l u g I n ( T B S _ X X X , $ a r g 1 , a r g 2 ) ;In this example, the plug-in identified by the key TBS_XXX is called.

Remark: when you call a plug-in's command for the first time this plug-in is automatically installed on the TBS

Page 9: TBS Manual

13/02/12 TBS Manual

9/34www.tinybutstrong.com/manual.php#php_mergeblock

instance ($TBS).

Installing a plug-in: Although some plug-ins are automatically installed, it can be useful in some other cases to make a manualinstallation. For this, use the constant TBS_INSTALL with the plug-in's key.Example:

$ T B S - > P l u g I n ( T B S _ I N S T A L L , T B S _ X X X ) ;In this example, the plug-in identified by the key TBS_XXX is installed.

Remarks:* A plug-in is installed relatively to a TBS instance (a variable $TBS for example). If you are using a second TBSinstance (for example $TBS2) then you will also need to install the plug-in on this instance. * A plug-in is installed automatically when you call one of its commands using the method PlugIn() (se above).

Versioning: the method PlugIn() is supported since TBS version 3.0.

Property Assigned:

Enables you to define information for a subsequent merging which can be automatic or manual.

Syntax: a r r a y $ T B S - > A s s i g n e d

Property Assigned is a PHP array defined by the user. Arguments for methods MergeBlock() and MergeField() can besaved there. Arguments have to be saved in a PHP array with numerical keys and ordered following the syntax ofthose 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 isthe 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 thisentry was merged.

Example of a manual merging:

$ T B S - > A s s i g n e d [ ' b ' ] = a r r a y ( ' b 1 , b 2 ' , & $ c n t _ i d , ' S E L E C T i d , n a m e F R O M t a b l e 1 ' ) ;. . .

$ T B S - > M e r g e B l o c k ( ' b ' ) ; / / m e r g e b l o c k b 1 a n d b 2 w i t h t h e S Q L q u e r y

Example of an automatic merging:

$ T B S - > A s s i g n e d [ ' b ' ] = a r r a y ( ' b 1 , b 2 ' , & $ c n t _ i d , ' S E L E C T i d , n a m e F R O M t a b l e 1 ' , ' a u t o ' = > ' o n l o a d ' ) ;

Example of merging fields:

$ T B S - > A s s i g n e d [ ' f 1 ' ] = a r r a y ( ' f 1 ' , $ d a t a , ' t y p e ' = > ' m e r g e f i e l d ' ) ;. . .

$ T B S - > M e r g e F i e l d ( ' f 1 ' ) ; / / m e r g e f i e l d f 1 w i t h t t h e a r r a y $ d a t a

Notes:- To merge an assigned block or field, you just have to call the corresponding method using only the name of theassigned key. You can add the argument Source = 'assigned', but this is optional because it is the default value. Inother words, $TBS->MergeBlock('b') is equivalent to $TBS->MergeBlock('b', 'assigned').- An assignment with 'auto'=>'onload' will be merged, of course, only if it is defined before calling theLoadTemplate() method.- You can pass some arguments by reference for you assignments. This is particularly useful for PHP 4 which ispassing object with a copy by default.

Versioning: property Assigned is supported since TBS version 3.5.

property NoErr:

Enables you to avoid all TinyButStrong error messages for next operations. Default value is false. The errors thatwere not displayed can however be returned with the special field [onshow..error_msg]. Furthermore you can checkthe presence of error using property ErrCount which counts TBS errors regardless of Noerr.

Syntax: b o o l e a n $ T B S - > N o E r r

Example: $ T B S - > N o E r r = t r u e ; / / n o m o r e e r r o r m e s s a g e i s d i s p l a y e d

Page 10: TBS Manual

13/02/12 TBS Manual

10/34www.tinybutstrong.com/manual.php#php_mergeblock

Property NoErr is useful in two cases:- For professional sites put into production for whom no error message can be displayed. Take care because you willhave no more indication about the good running of the merge. It is often more judicious to use parameter noerrwhich enables you to avoid messages concerning one particular TBS tag. - For merges that do not accept TinyButStrong basic error messages. For example, an OpenOffice document will notopen correctly if a TBS error occurs. Use $ T B S - > N o E r r = t r u e and the field [onshow..error_msg] to display TBS errors ina viewable place of your OpenOffice document.

Versioning:- Property NoErr is supported since TBS version 3.0. - Special field [onshow..error_msg] is supported since TBS version 3.5.0.

property Render:

Indicates how the merging ends.The value must be a combination of the following constants.The default value is (TBS_OUTPUT + TBS_EXIT).

Syntax: i n t $ T B S - > R e n d e r

The Render property changes the behavior of the Show() method.

Constant Description

TBS_NOTHING Indicates that none of the actions below are processed at the end of the merge.

TBS_OUTPUT Indicates that the result of the merge must be displayed. TBS uses the Php command Echo.

TBS_EXIT Indicates that we have to quit the script just after the end of the merge.

property Source:

This property contains the source of the template currently merged. It is read/write. When TinyButStrong processes a merging (when using the MergeBlock() method for example), the Source propertyis modified immediately.

Syntax: s t r i n g $ T B S - > S o u r c e

Notes:- The LoadTemplate() method loads a file into the Source property and merges the [onload] tags automatically.Thus, Source may be different from the original template after LoadTemplate(). - The Show() method merges [onshow] tags automatically before to display the result.

In order to load a template stored into a Php variable, you can code:

$ T B S - > S o u r c e = $ m y _ t e m p l a t e ;$ T B S - > L o a d T e m p l a t e ( n u l l ) ; / / r u n p l u g - i n s i f a n y , a n d m e r g e s [ o n l o a d ] t a g s i f a n y

In order to store the result at the end of the merging, you can code:

$ T B S - > S h o w ( T B S _ N O T H I N G ) ; / / t e r m i n a t e t h e m e r g i n g w i t h o u t l e a v i n g t h e s c r i p t n o r t o d i s p l a y t h e r e s u l t

$ r e s u l t = $ T B S - > S o u r c e ;

property TplVars:

Contains the array of template variables corresponding to current template.

Syntax: a r r a y $ T B S - > T p l V a r s

You can define template variables using one or several onload automatic fields with parameter tplvars. Allparameters that follow parameter tplvars are added to the TplVars property when the LoadTemplate() method iscalled.

Example: [onload;tplvars;template_version='1.12.27';template_date='2004-10-26']This TBS tag will create two items equivalent to the PHP code:

$ T B S - > T p l V a r s [ ' t e m p l a t e _ v e r s i o n ' ] = ' 1 . 1 2 . 2 7 ' ; $ T B S - > T p l V a r s [ ' t e m p l a t e _ d a t e ' ] = ' 2 0 0 4 - 1 0 - 2 6 ' ;

Remarks:- Parameter tplvars works only with onload automatic fields.- You can use parameter tplvars several times in the same template.

Object Oriented Programming (OOP):

Page 11: TBS Manual

13/02/12 TBS Manual

11/34www.tinybutstrong.com/manual.php#php_mergeblock

TinyButStrong integrate a technique to call methods or properties of objects that you've coded at the PHP side.

Calling methods of a class without created object:

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 thedescription of the corresponding feature).

Calling created objects:

TBS has an ObjectRef property that is set to false by default, and that you can use to reference your objectsalready created. You can reference an object directly on the ObjectRef property, or you can reference some usingPHP arrays.Example:

$ T B S - > O b j e c t R e f = & $ M y O b j e c t 1 ;

You can use an array if you have several objects reference:$ T B S - > O b j e c t R e f [ ' i t e m 1 ' ] = & $ M y O b j e c t 1 ;

$ T B S - > O b j e c t R e f [ ' i t e m 2 ' ] = & $ M y O b j e c t 2 ; You can use as many levels as you wish:$ T B S - > O b j e c t R e f [ ' i t e m 3 ' ] [ ' a ' ] [ 0 ] = & $ M y O b j e c t 4 ;

Remarks:* Think to use the assignment by reference using "=&" instead of "=", otherwise a copy of the object will becreated.* Since an object is referenced under ObjectRef, its sub objects will also be accessible by the TBS syntax.

• Using ObjectRef in automatic fields: Use the symbol '~' to call what is referenced under ObjectRef.For example (valid for both [onload], [onshow] and [var]):

The field Will call

[onshow.~propA] $ T B S - > O b j e c t R e f - > p r o p A

[onshow.~propA.propB] $ T B S - > O b j e c t R e f - > p r o p A - > p r o p B

[onshow.~item2.propA] $ T B S - > O b j e c t R e f [ ' i t e m 2 ' ] - > p r o p A

[onshow.~item2.methX] $ T B S - > O b j e c t R e f [ ' i t e m 2 ' ] - > m e t h X ( )

[onshow.~item2.methY(a,b)] $ T B S - > O b j e c t R e f [ ' i t e m 2 ' ] - > m e t h Y ( ' a ' , ' b ' )

Remark: TBS proceeds to a coherence control, it will determine itself whether your automatic field definition is calling toObjectRef via an array's item, an object's property or an object's method. Anyway, take care that your automaticfield must call a value at the end, not an object.

• Using ObjectRef in other TBS features: The following TBS features support the call to the methods of objects referenced under ObjectRef.

Feature Example

Parameter ondata [blk1.column1;block=tr;ondata=~item1.methA]

Parameter onformat [blk1.column2;onformat=~item1.methB]

Method LoadTemplate() $TBS->LoadTemplate('mytemplate.htm','=~item1.methC');

Method MergeField() $TBS->MergeField('myfield','~item1.methD',true);

Method MergeBlock() $TBS->MergeBlock('blk1','~mydb','SELECT * FROM t_table');

Remark: Methods call using this technique must respect the function syntax expected by the feature (see thedescription of the corresponding feature).

Template side:

You design your template by placing TBS tags in the places where data items should appear.

There are two types of TBS tags: Fields and Blocks.

A TBS Field is a TBS tag which has to be replaced by a single data item. It is possible to specify a display format and alsoother parameters. The syntax for TBS Fields is described below.

A TBS Block is an area which has to be repeated. It is defined using one or two TBS fields.Most often, it is the row of an HTML table. The syntax for TBS Blocks is described below.

TBS Fields:

Page 12: TBS Manual

13/02/12 TBS Manual

12/34www.tinybutstrong.com/manual.php#php_mergeblock

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 modifythe displayed value.

Syntax: TEMPLATE ... [FieldName{;param1}{;param2}{;param3}{...}] ... TEMPLATE

Element Description

FieldName The name of the Field.Warning: names that begin with onload, onshow and var.are reserved for automatic fields.

param1 Optional. One or more parameters from the list below and separated with ';'.Some parameters can be set to a value using the equal sign '='.

Example: frm=0.00If the value contains spaces, semicolons or quotes, then you can use single quotes as delimiters.

Example: frm='0 000.00'To specify a literal single quote, escape it with a second single quotes.

Example: ifempty='hello that''s me'

A parameter can contain embedded TBS fields, but only under special circumstances:- the embedded field is merged before the parent field,- the embedded field if a [var] field placed into a parameter file, script, if, then, else or when.In the other cases; the embedded TBS field will not be processed and will be taken as is, like text.Examples:

[x;htmlconv=[var.y]] : [var.y] will not be merged and parameter "htmlconv" will have an unvalidvalue.[x;if [var.y]=1] : [var.y] will be correctly merged and the "if" condition will be correctly evaluated.

Field's parameters:

Parameter Description

htmlconv=val Ennables you to modify the special character conversion for this TBS field only. Note that thespecial character conversion used by default for all TBS fields is the one defined byLoadTemplate(). It is often corresponding to an Xml/Html charset but not necessary.The value val can be one of the following keywords:

yes (default value) Performe the default special character conversion, including newlines.

no No special character conversion. Useful to modify Xml/Html source.

nobr Let the default special character conversion, except new lines (useful for <pre>tags for example).

wsp Preserve white spaces (useful for spaces at the beginning of lines).

esc No special character conversion and double the single quote characters (').

js Convert the data item to a string that can be inserted between JavaScript textdelimiters.

url Convert the data item to a string that can be inserted inside an URL. (supportedsince TBS version 3.5.2)

utf8 Convert the data item into UTF-8. (supported since TBS version 3.6.0)

look Deprecated. Performe the default special character conversion only if noXml/Html entities are found inside the data item.

You can specify several values using seperator '+'. Example : htmlconv=yes+js

. (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. Thisparameter is very useful when it is too difficult for the template designer to place a TBS fieldinto an attribute.The value path must indicate the place of the attribute relatively to the current field.If the attribute doesn't exist in the specified tag, then it is created.If the attribute already exists in the specified tag and it has already a value, then the fieldreplaces all the current value.You can chose to place the field as an added value using parameter attadd.You can complete the attribute's value by applying a mask to it using parameter ope=msk.You can delete the attribute in case of empty value using parameter magnet=#.

Syntax for value path: [+][tag1+tag2+tag3+...#]attributeBy default the attribute is searched before the current field. But if '+' is the first character ofthe path, then it is searched after. If no tag list is specified, then the attribute is looked at inthe first tag met in the search direction. If a tag list is used, tag1 is search first, then tag2, ...regardless of the direction of the search (before/after). You can put a tag name between oneor several bracket levels in order to specify that the searched tag must embed the currentfield.

Examples:

[onshow.x;att=class] moves into attribute 'class' of the first tag placed before.

Page 13: TBS Manual

13/02/12 TBS Manual

13/34www.tinybutstrong.com/manual.php#php_mergeblock

[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 thefirst <table> placed before.

Notes:- Method MergeBlock() cannot move a TBS field over another TBS field placed after it. Thismakes a TBS error to occur.- When the attribute has no value before the field is moved, then TBS chooses what stringdelimiter to use regarding other attributes (XML/HTML accepts both (") and (')). You can forcethe delimiter you need using property $TBS->AttDelim.

Versioning: Parameter att is supported since TBS version 3.5.0

attadd To be used with parameter att. Indicate that the field is added into the attribute's value,instead of being replacing the attribute's value. Please note that the added value won't besimply concatenated with previous values, it will be added with a space character separatorin 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 = ' s t y l e 2 ' then we obtain <div class="style1 style2">

There is no way for now to simply concatenate the field's value with the previous attribute'svalue. But instead, you can use parameter ope=msk in order to apply a mask to the field'svalue.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

atttrueor

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 withthe format attribute="attribute" in order to mean TRUE, or ommited in the tag in order tomean FALSE.If atttrue is set with a given value, then the boolean attribute will be TRUE (present) if thefield is equal to this value, otherwise it will be FALSE (omitted).If atttrue is set with no value, then the boolean attribute will be TRUE (present) if the field'svalue is non empty, and it will be FALSE (omitted) if the field's value is empty. Examples:

<input type="checkbox">[onshow.accept;att=selected;atttrue=1]

Versioning: Parameter atttrue is supported since TBS version 3.6.0

magnet=tagor

magnet=expr

Assign a magnet XML/HTML zone to the TBS field. A magnet tag is kept as is when the fieldhas a value, and is deleted when the field is null or empty string. Parameter magnet supportsthe same syntax as parameter block, i.e. that expr must be an XML/HTML tag or a TBSextended block expression.

Example:(<a href="[onshow.link;magnet=a]">click here</a>)Result for $ l i n k = ' w w w . t b s . c o m ' : (<a href="www.tbs.com">click here</a>)

Result for $ l i n k = ' ' : ()

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 usingparameter mtype (see below).Since TBS version 3.3.0, parameter ope has keywords (nif, minv, mok and mko) that improveparameter magnet. Remark: the parameters if then else are processed before parameter magnet.

mtype=val To be used with parameter magnet. Define the magnet type.

Value Magnet behavior when field is null or empty stringm*m That's the default value. Delete the pair of tags that surrounds the TBS field.

Everything that is between them is deleted also. The field can be put inside oneof the tags.

Example:(<a href="[onshow.link;magnet=a]">click here</a>)Result for $ l i n k = ' w w w . t b s . c o m ' : (<a href="www.tbs.com">click here</a>)Result for $ l i n k = ' ' : ()

m+m Delete the pair of tags that surrounds the TBS field, but keeping everything elsethat is between the tags.

Example:(<a href="mailto:[blk.email;magnet=a;mtype=m+m]">[blk.name]</a>)Result for $ e m a i l = ' m e @ t b s . c o m ' : (<a

href="mailto:[email protected]">MyName</a>)Result for $ e m a i l = ' ' : (MyName)

Page 14: TBS Manual

13/02/12 TBS Manual

14/34www.tinybutstrong.com/manual.php#php_mergeblock

m* Delete the single tag that is before the field, and everything that is between thetag and the field.

Example 1: <img href="[onshow.link;magnet=img;mtype=m*]"> Example 2: <br> [onshow.address;magnet=br]*m Delete the single tag that is after the field, and everything that is between the

tag and the field.

Example: [onshow.address;magnet=br;mtype=*m]<br>

comm Widen the bounds of the TBS Field up to the bounds of the commentary Html tags whichsurround it, or up to another specified couple of XML/HTML tags.Example:

xxx <!-- [myfield;comm] here some comments --> yyy

or

xxx <div> [myfield;comm=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 VisualHTML Editor (such as Dreamweaver or FrontPage).Versioning: Support for other XML/HTML tags was added in TBS 3.0.

noerr Avoid some of the TBS Error messages. When a message can be cancelled, it is mentioned inthe message.

file=filename Replace the field with the contents of the file.Filename can be a string or an expression.You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression.If parameter script is used by omitting the filename value (example:[onshow.file;script;subtpl]), then the field's value is used for the file name.If the file is not found, then it will be searched in the folder of the last loaded template (sinceTBS version 3.2.0).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 isignored. 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.See also: getbody script

getbody=taglist To be used with parameter file or script. Indicates that not all the file contents is loaded butonly some XML/HTML parts of it defined with the tag list. The tags of the list must beseparated with plus (+), and placed between parentheses if you want the tags themselves tobe retrieved with their content. If the file has several XML/HTML part of a tag, all those partswill be automatically concatenated. If parameter getbody is used without value, then the<body> tag is taken by default.Example:

[onload;file=header.htm;getbody=(script)+(style)+body]

Versioning: parameter getbody is supported since TBS version 3.0. In previous versions, itwas automatically processed when using parameter file. Now it becomes explicit. The tag list is supported since TBS version 3.5.0. Before this version, the value of getbody canbe only one tag without parentheses.

rename old=new To be used with parameter file or script. Renames TBS blocks and fields in the subtemplatebefore it is inserted. You can define several block to rename by separate them with coma. If anew 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 themain template. Example:

Address 1: [onload;file=address.htm]Address 2: [onload;file=address.htm;rename town1=town2,zip1=zip2,email=]

Versioning: parameter rename is supported since TBS version 3.5.1.See chapter 'Subtemplates' for more details about subtemplates.

script=filename Execute the Php script just before replacing the TBS field.Filename can be a string or an expression.You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression.If parameter script is used by omitting the filename value (example:[onshow.file;script;subtpl]), then the field's value is used for the file name.If the file is not found, then it will be searched in the folder of the last loaded template (sinceTBS version 3.2.0).

* Take care that in your script variables will be obsiously local instead of global. This isbecause the script is called from a TBS method. In order to define or reach global variablesin your script, you have to use the Php instruction global or the array $ G L O B A L .

* TBS gives to you predefined local variables that can be used in your script:

Page 15: TBS Manual

13/02/12 TBS Manual

15/34www.tinybutstrong.com/manual.php#php_mergeblock

- $CurrVal refers to the current value of the field. It can be modified. - $CurrPrm refers to the array of field's parameters.- $this refers to the current TBS instance. (See parameter subtpl for good usage)

* If the filename expression (or the value of the field) return an empty string (''), thenparameter script is ignored and no error occurs. You can use this behavior in order to use aconditional insertion.

See chapter 'Subtemplates' for more details about how to use this parameter in subtemplatemode.

subtpl To be used with the parameter script or parameter onformat.Activate the subtemplate mode during the script or function execution.See chapter 'Subtemplates' for more details.

if expr1=expr2 Display the data item only if the condition is verified, otherwise display nothing unlessparameter then or else are used.Supported operators are:

= or == equal!= not equal+- greater than+=- greater than or equal to-+ less than-=+ less than or equal to~= match the regular expression (since TBS version 3.0)

Both expr1 and expr2 must be string or numerical expressions.You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression.The expressions may contain other TBS fields, but you have to make sure that they aremerged before the containing field.Since TBS version 3.0, it is also possible to define several couples of if/then in the same field.See parameters then and else for some examples.

then val1 If the parameter if is defined and its condition is verified, then the data item is replaced withval1.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']

You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression.

else val2 If the parameter if is defined and its condition is not verified, then the data item is replacedwith val2.Example:

[onshow.error_id;if [val]=0;then 'no error';else 'error found']

You can use the keyword [val] inside the expression to insert the current data item.You can use [var] fields inside the expression.

onformat=fct_name Indicates the name of a user Php function that will be executed at the time when the value isformated for the merge. This allows typically to modify the text to display.Since TBS version 3.0, it's also possible to indicate a method of a class (see OOP).The function fct_name must have the following syntax: f u n c t i o n f c t _ n a m e ( $ F i e l d N a m e , & $ C u r r V a l , { & $ C u r r P r m , { & $ T B S } } ) { . . . }

Argument Description

$FieldName The name of the current field (read only).

$CurrVal The value of the current field. (Don't forget the & character in the statement).The function is supposed to change this value in order to format it.

$CurrPrm Optional. The PHP array containing the parameters for the current field (Don't

forget the & character in the statement).

$TBS Optional. Gives the current TBS instance. (Don't forget the & character in the

statement).Use this argument with lot of care. It is used sometimes for the subtemplatemode.

Example:

HTML: [onshow.x;onformat=f_to_utf8]

P H P :f u n c t i o n f _ t o _ u t f 8 ( $ F i e l d N a m e , & $ C u r r V a l ) {

$ C u r r V a l = u t f 8 _ e n c o d e ( $ C u r r V a l ) ;

}

See chapter 'Subtemplates' for more details about how to use this arguments in subtemplatemode.Since TBS version 3.6.0, it's possible to limit the allowed PHP functions for parameteronformat. See create a new TBS object.

protect=val Enables you to protect or unprotect the data item to be merged by replacing the characters '['with their corresponding XML/HTML code '&#91;'. The value val can be one of the followingkeywords:

Page 16: TBS Manual

13/02/12 TBS Manual

16/34www.tinybutstrong.com/manual.php#php_mergeblock

yes: (default value) data item is protected. no: data item is not protected.By default, all data merged with a template is protected except if it's a file inclusion. It isstrongly recommended to protect data when it comes from free enter like on a forum forexample.Nevertheless, it is possible to disable the protection by default if you set property $TBS->Protect to false.

ope=action Makes one or several operations on the value to merge. You can define several operations tobe processed in order by separating them with coma (,).Example:

[onshow.x;ope=add:-1,mod:10]

Supported operations are:

max:n Limit the text string to a maximum of n characters. If the string is cut, then itsend is replaced with dot lines '...'.

Example: [onshow.caption;ope=max:10]- Add parameter maxhtml to indicate that the value before merging can containHtml characters. - Add parameter maxutf8 to indicate that the value before merging can containUTF8 characters. Versionning: maxutf8 is supported since TBS version 3.5.2.- Add parameter maxend to change the cutting symbol.

Example: [onshow.caption;ope=max:10;maxhtml;maxend='+']

mod:n Apply the modulo n to the value to merge. Example:[onshow.numlig;ope=mod:7]

add:n Add the numeric n to the value to merge. Example:[onshow.number;ope=add:-1]

mul:n Mutlyplies the value to merge by the numeric n.

div:n Divises the value to merge by the numeric n.

list If the value before merging is a Php Array, then its items are displayedseparated with a coma (,).

Example: [onshow.myarray;ope=list]Add parameter valsep in order to change the item separator.

Example: [onshow.myarray;ope=list;valsep='+']

mok:x (means "magnet ok") To be used with parameter magnet. The TBS fields is neverdisplayed, but the magnet tag is kept when the value of the field is equal to 'x'.The magnet tag is deleted in other cases. You can define several values to keepthe magnet tag by defining several mok. Example:[onshow.x;magnet=div;ope=mok:1,mok:2] (mok is supported since TBS version3.5.2)

mko:x (means "magnet ko") To be used with parameter magnet. The TBS fields is neverdisplayed, but the magnet tag is deleted when the value of the field is equal to'x'. The magnet tag is kept in other cases. You can define several values todelete the magnet tag by defining several mko. Example:[onshow.x;magnet=div;ope=mko:1,mko:2] (mok is supported since TBS version3.5.2)

nif:x (means "null if") If the value is equal to 'x' then it is replaced with '' (empty

string). This operation is designed to make parameter magnet to work with othervalues than ''. (supported since TBS version 3.3.0)

minv (means "magnet invisible") Replace the value with '' (empty string) but parametermagnet will consider the old value. This operation is designed to make totalyinvisible a TBS field which do magnet stuffs. (supported since TBS version 3.3.0)

msk:x (means "mask") Apply a mask to the value. Characters '*' in the mask will bereplaced by the original value. Example: [onshow.img_id;ope=msk:img_*.gif](supported since TBS version 3.6.0)

lower Convert the value to lower case. (supported since TBS version 3.8.0)

upper Convert the value to upper case. (supported since TBS version 3.8.0)

upper1 Convert the value to upper case for the first character only. (supported sinceTBS version 3.8.0)

upperw Convert the value to upper case for the first character of each word. (supportedsince TBS version 3.8.0)

utf8 Can be used with max, upper, lower, upperw in order to indicate that the valueis UTF8 encoded. upper1 is not supported in UTF8. (supported since TBS version3.8.0)

Versioning:- Parameter ope is supported since TBS version 3.0. It replaces parameter max which doesn'texist since this version.- Multiple operations and 'mul" and "div" are supported since TBS version 3.2.0

frm=format Specify a format to display for a data item which type is date/time or numeric. It is possible touse a conditional format which changes depending on the sign of the value. The format isconsidered as numeric type as soon as it contains the character 0, otherwise it is consideredas date/time type.

Date-time format:

Page 17: TBS Manual

13/02/12 TBS Manual

17/34www.tinybutstrong.com/manual.php#php_mergeblock

It is a VisualBasic like format. The following keywords are recognized:d, dd, ddd, dddd: number of the day, number of the day in two digits, short name of the

day, full name of the day. Add keyword (locale) to display localenames.

xx displays st, nd, rd or th depending to the number of the day.w number of the day in the week (from 0 to 6)m, mm, mmm, mmmm: number of the month, number of the month in two digits, short name

of the month, full name of the month. Add keyword (locale) to displaylocale names.

yy, yyyy: year in two digits, full year.hh, rr, nn, ss: hour-24, hour-12, minutes, seconds forced on two digits.h, r hour-24, hour-12ampm, AMPM : "am" or "pm" signal , "AM" or "PM" signal.(locale) Display locale day and month's names. The locale language can be set

using the PHP function s e t l o c a l e ( ) . It works only if locale parameters

have been set on the server. For PHP reasons, in locale mode xx doesnot work and d does like dd.

Other characters are kept. It is possible to protect the strings inside by putting them betweendouble quotes (").

Examples:

[fld;frm=mm/dd/yyyy] will display 12/21/2002[fld;frm='yyyy-mm-dd hh:nn:ss'] will display 2002-12-21 15:45:03

Versioning:- Keywords ampm and AMPM are supported since TBS version 3.0.- Keyword hm was supported since TBS 3.0 and is deprecated an replaced with keyword rrsince TBS version 3.2.0.- Keywords rr, r, and h are supported since TBS version 3.2.0.- Keyword (locale) is supported since TBS version 3.4.0.

Numeric format:

To define the decimal part, use an expression like '0d0...' where 'd' is the decimal separator ,and '0...' is a continuation of zeros corresponding to the number of decimals.If there is no decimal, use the format '0.' (with a dot).

To define a thousand separator, use an expression like '0t000d...' where 't' is the thousandseparator. 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' representsthe number of digits you want to have. If there is no decimal, use the format '0000.' (with adot). 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 morezeroes placed to the right will be taken as a format, other characters will be kept.

Examples:

Value Field Display

2456.1426 [fld;frm='0.000'] 2456.143

[fld;frm='$ 0,000.00'] $ 2,456.14

[fld;frm='$ 0,000.'] 2,456

[fld;frm='000000.'] 002456

0.2537 [fld;frm='0.00 %'] 25.37%

[fld;frm='coef 0.00'] coef 0.25

Conditional formats:

You have the possibility to define up to 4 conditional formats when the value is respectivelypositive, negative, zero or null (or empty string). Conditional formats must be separated by a'|' character. Each conditional format is optional.

Examples:

Value Field Display

2456.1426 [chp;frm='+0.00|-(0.00)|*|empty'] +2456.14

-156.333 [chp;frm='+0.00|-(0.00)|*|empty'] -(156.33)

0 [chp;frm='+0.00|-(0.00)|*|empty'] *

null [chp;frm='+0.00|-(0.00)|*|empty'] empty

-8.75 [chp;frm='+0.00|-(0.00)'] -(8.75)

locale Deprecated since TBS version 3.4.0.

Page 18: TBS Manual

13/02/12 TBS Manual

18/34www.tinybutstrong.com/manual.php#php_mergeblock

It does the same as the keyword (locale) used in parameter frm.

tplfrms Enables you to define formats in the template that you can reuse for parameter frm. Worksonly 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 programmusing TplVars property. Works only with onload automatic fields.

Order of processing parameters:

When you whant to use several paremeters in the same TBS field, then it can be intersing to undertsand in whichorder they are processed.Each parameter is changing the value to be merged, but the source from where the value is is taken is not changed.

Order:1) -> Retreiving the value of the field to be merged.2) -> Changing the value using parameters: 2.1) -> onformat 2.2) -> ope / plug-ins OnOperation 2.3) -> frm / XML/HTML or other char conversion 2.4) -> if 2.5) -> file 2.6) -> script 2.7) -> att 2.8) -> . / ifempty / magnet3) -> Inserting the value in the template.

Automatic fields

Automatic fields enable you to automatically merge PHP global variables when some events occur.For example [onload.x] will be merged with the global variable $x when the LoadTemplate() method is called.

Automatic fields can only merge PHP variables when they are global. There is no way to merge a variable which islocal to a function, unless you make a reference to it with a global variable, or if you merge it using MergeField().Automatic fields can also merge TBS special information (see Special automatic fields), or data of the ObjectRefproperty (see Objet Oriented Programming).

There are three types of automatic fields:- [onload] fields, which are automatically merged when the LoadTemplate() method is called.- [onshow] fields, which are automatically merged when the Show() method is called.- [var] fields, which are automatically merged when the field they are embedded in is also merged itself, but it worksonly if they are placed into a parameter file, script, if, then, else or when.

Versioning:- Automatic fields [onload] and [onshow] are supported since TBS version 3.2.0. For compatibility with versions priorto 3.2.0, remaining [var] fields are still merged as if there were [onshow] fields but is it recommended to use real[onshow] fields instead.- [var] are processed into parameter then and else since TBS version 2.02.

Automatic fields may or may not have a sub name, like x in [onload.x], [onshow.x] or [var.x]. An automatic fieldwithout sub name will be merged with an empty string value (''). Example: [onload;file=header.html] this field insertsa subtemplate when LoadTemplate() method is called.

An automatic field having a sub name will be merged with the corresponding global PHP variable.If the global variable doesn't exist at this moment, then a TBS error is displayed, unless you add parameter noerr.

Examples:

[onload.x] this field will be merged with the global variable $x when LoadTemplate() is called.[onshow.x] this field will be merged with the global variable $x when Show() is called.[b1.col1;if [val]=[var.x];then 'good'; else 'bad'] : the [var.x] field is merged in the same time as [b1.col1].

You can also merge array's items, object's properties or object's methods using a dot (".") as separator. Resourcevariables are ignored.For example (valid for both [onload], [onshow] and [var]):

[onshow.tbl.item1] will display $ t b l [ ' i t e m 1 ' ]

[onshow.tbl.item2.a.0] will display $ t b l [ ' i t e m 2 ' ] [ ' a ' ] [ 0 ]

[onshow.obj.prop1] will display $ o b j - > p r o p 1

[onshow.obj.methA] will display $ o b j - > m e t h A ( )

[onshow.obj.methB(x,y)] will display $ o b j - > m e t h B ( ' x ' , ' y ' )

[onshow.tbl.item3.prop2.item4 will display $ t b l [ ' i t e m 3 ' ] - > p r o p 2 [ ' i t e m 4 ' ]

Page 19: TBS Manual

13/02/12 TBS Manual

19/34www.tinybutstrong.com/manual.php#php_mergeblock

Versioning: calling methods with arguments from an automatic field is supported since TBS version 3.0.

Note: You can also force the merge of [var] fields or other types at anytime using the MergeField() method.

Embedded automatic fieldsAn embedded TBS field is never merged, unless :- it is merged before the parent field,- il is a [var] field placed into a paremeter file, script, if, then, else or when.

Examples:

[onload;if [onload.x]=1;then 'yes';else 'no']This example will always display 'no', because the embedded [onload.x] fild will never be evaluated. It is betterto use [onload;if [var.x]=1;then 'yes';else 'no'] instead, or better : [onload.x;if [val]=1;then 'yes';else 'no']

[b1.nom;block=tr;headergrp=[var.x]]In this example, [var.x] will not be merged yet when you call $ T B S - > M e r g e B l o c k ( ' b 1 ' , . . . )The header will then be defined badly. It needs one of those: - using an onload field: [b1.name;block=tr;headergrp=[onload.x]]- calling $ T B S - > M e r g e F i e l d ( ' v a r ' ) avant $ T B S - > M e r g e B l o c k ( ' b 1 ' , . . . )

- using a customized field name: [b1.name;block=tr;headergrp=[zzz]] manually merged with $ T B S -> M e r g e F i e l d ( ' z z z ' , $ x )

Security: how to limit automatic fields usage in templates?

You can limit the automatic fields usage by defining a prefix for allowed PHP variables. For details, see create a newTBS object.

Prevent from processing automatic fields [onload] and [onshow]

Properties $TBS->OnLoad and $TBS->OnShow enable you to cancel the processing of [onload] and [onshow] fields.Those properties accept only true of false values. This can be very useful especially, but not only, for some TBS plug-ins. Note that [var] fields are automatically processed even if $ T B S - > O n S h o w = f a l s e .

Example: $ T B S - > O n S h o w = false ;

Properties OnLoad and OnShow are supported since TBS version 3.6.0.

Special automatic fields :

A Special [var] field is a TBS Field which displays data provided by the TinyButStrong system.The name of a Special [var] field has to begin with 'var..', followed by a keyword in the list below.The parameters for standard TBS Fields are available for Special [var] fields.

Example: Date of the day : [onshow..now;frm='mm-dd-yyyy']

(valid for both onload, onshow et var)

Name Description

onshow..now Date and hour of the server.

onshow..version The version of TinyButStrong.

onshow..script_name The name of the PHP file currently executing.

onshow..template_name The name of the last loaded template file.It is the name given to the LoadTemplate() method.

onshow..template_date The creation date of the last loaded template file.

onshow..template_path The directory of the last loaded template file.It is the directory given to the LoadTemplate() method.

onshow..tplvars.* The value of an item set in the TplVars property.('*' must be the key of an existing item in the array)

onshow..cst.* The value of a PHP constant.(* must be the name of an existing constant)

onshow..tbs_info Information about TBS and installed plug-ins.

onshow..error_msg Display errors that have been avoid during the time when property NoErr is set to true.

Versioning:- special var fields "cst" and "tbs_info" are supported since TBS version 3.2.0.- "error_msg" is supported since TBS version 3.5.0.

TBS Blocks:

Page 20: TBS Manual

13/02/12 TBS Manual

20/34www.tinybutstrong.com/manual.php#php_mergeblock

A TBS block enables you define a zone and to display data from a record source.You can define a TBS block using one or two TBS tags (see below).

Merging with data: Merging a block with data is done using the MergeBlock() method. When a TBS block is merged with data, it isrepeated as many times as there are records; and the associated TBS fields are replaced by the value of thecolumns 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 bythe name of the column to display and separated by a dot.Examples:

- [Block1.ColA] This field will display the value of column ColA when block Block1 is merged. - [Blokc1.ColB;frm='dd-mm-yyyy'] Another field but with a TBS parameter.

Since TBS version 3.5.0 column names with spaces are accepted.

Remark: when two separated blocks have the same name, then they will be considered has two sections of thesame block. All content placed between those two sections of a block will be ignored and deleted during themerging. See sections of blocks to know more about sections.

Block syntaxes:

There are three possible syntaxes to define a TBS block:

Explicit Syntax:

Two TBS tags are used. One for the beginning of the block and another for the end of the block.

Example:TEMPLATE...[BlockName;block=begin;params]...TEMPLATE...[BlockName;block=end]...TEMPLATE

Those TBS tags for the block definition will be deleted during the merging.

Relative Syntax:

The block is defined by a pair of opening-closing XML/HTML tags which is given by a single TBS tag.

Example:TEMPLATE...<tag_name...>...[BlockName;block=tag_name;params]...</tag_name...>...TEMPLATE

This TBS tag for the block definition must be placed between the pair of XML/HTML tags.This TBS tag will be deleted during the merging.Remark: You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for moredetails.

Simplified Syntax:

An associated TBS field is used to define the block in a relative way (see the relative syntax above).

Example:TEMPLATE...<tag_name...>...[BlockName.ColumnName;block=tag_name;params]...</tag_name...>...TEMPLATE

The TBS tag for the block definition (i.e. the block=... parameter) must be placed between the pair of XML/HTMLtags. You are nor obliged to put the parameter block on the first field, it can be any of them inside the zonedefined by the block. Remarks: • You should not repeat the parameter block=... on each fields of the bloc, only one is enough. If you placeseveral of them, this will be accepted by TBS but it may bring confusions about complementary parameters forblock.• You can aslo define a block's zone by a combination of XML/HTML tags. See parameter block for more details.

Which syntax to use?

The 'absolute' syntax is rarely used with Visual Editors because TBS tags have often to be placed between twoXML/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 tohide 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>

Element Description

BlockName The name of the TBS block.

params Optional. One or several parameters from the list below. Separated with ';'.

block=begin Indicates the beginning of the block.

Page 21: TBS Manual

13/02/12 TBS Manual

21/34www.tinybutstrong.com/manual.php#php_mergeblock

block=end Indicates the end of the block.

block=tagor

block=expr

Define a block bounded between the opening XML/HTML tag <tag...> and the closing XML/HTML tag</tag> which surround the TBS tag. The couple of indicated XML/HTML tags are integral part of thebloc.Example:

<table id="tab1"> <tr><td>[b1.field1;block=tr]</td></tr> </table>The block is defined by the zone framed by pointillets.

Special marks:

block=_ Define a block on the text line which holds the TBS tag. A text line always ends with anew-line char. New lines for Windows, Linux and Mac are supported. This feature isvery useful for a template with text contents for example.

block=tag/ By adding character / at the end of the tag's name, TBS won't retrieve the closingtag. The block will be defined on the single opening XML/HTML tag which contains theTBS tag. This can be useful to multiply an image for example.

Versioning: special marks "_" and "/" are supported since TBS 3.1.0.

Extended blocks: You can extend the block's zone (or the section's zone) beyond the simple XML/HTML tag or specialmarks by using the following expressions:

Note that special marks (see above) can be used for extended blocks.

To extend the block's zone on several successive tags:

<table> <tr>[b1.field1;block=tr+tr+tr]</tr><tr>...</tr><tr>...</tr> </table>Note: you can specify tags of different types

To extend the block's zone on several successive tags placed before:

... <span>...</span><div>[b1.field1;block=span+(div)]</div> ... Other example: ... <span>...</span> <div>[b1.field1;block=span+(div)+table]</div> <table>...</table> ... The tag placed bewteen brackets means the one which contains the block's definition.

To extend the block's zone on a tag of the same type but with a higher encapsulation level:

<div> <div> [b1.field1;block=((div))] </div> </div> The number of bracket means le encapsulation level of the tags.

Versioning : The Extended Blocks feature is supported since TBS version 3.0. Before that, you had touse parameters 'extend' and 'encaps' which are not supported anymore.

Block's parameters:

Parameter Description

nodata Indicates a section that is displayed only if there is no data to merge.

Example:

[b1.field1;block=tr] [b1.field2]

[b1;block=tr;nodata]There is no data.

For more information about sections, see the chapter 'Sections of blocks'.

bmagnet=tagor

bmagnet=expr

Indicates an XML/HTML zone which must be deleted if the block is merged with no record (anemprt query, for example, or a PHP Array with no items). Parameter bmagnet supports thesame syntax as parameter block, i.e. that expr must be an XML/HTML tag or a TBS extendedblock expression.Example:

[b1.field1;block=tr;bmagnet=table] [b1.field2]

In this example, the table will be deleted if there is no record to merge.

Remark: Value null is not accepted by MergeBlock() method as a data source, and it makes a TBS errorinstead of deleting the bmagnet zone. If you data source may be null, then you should makea check previously. Example:

i f ( i s _ n u l l ( $ d a t a ) ) $ d a t a = a r r a y ( ) ;

$ T B S - > M e r g e B l o c k ( ' b 1 ' , $ d a t a ) ;

Versioning: parameter bmagnet is supported since TBS version 3.0.

headergrp=colname Indicates a header section that is displayed each time the value of column colname changes.colname must be a valid column name returned by the data source.Since TBS version 3.3.0, colname can also be a virtual column # or $, and it also support the

Page 22: TBS Manual

13/02/12 TBS Manual

22/34www.tinybutstrong.com/manual.php#php_mergeblock

subitems syntaxe of TBS fields.You can define several headergrp sections with different columns. Placement's order ofheadergrp sections in the block can modify the result. For more information about sections, see the chapter 'Sections of blocks'.

footergrp=colname Indicates a footer section that is displayed each time the value of column colname changes.See headergrp.

splittergrp=colname Indicates a splitter section that is displayed each time the value of column colname changes.See headergrp.

parentgrp=colname Indicates a parent section that is displayed each time the value of column colname changes.Unlike other sections, a parentgrp section allows normal sections inside itself. It's a way todefine both a header and a footer in one section.

serial Indicates that the block is a main block which contains serial secondary blocks.For more information, see the chapter 'serial display (in columns)'.

p1=val1 Indicates the use of a dynamic query. All the occurrences of the string '%p1%' found in thequery 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 thearguments of such a Php function to edit records before they are merged. The function musthave the following syntax: f u n c t i o n f c t _ n a m e ( $ B l o c k N a m e , & $ C u r r R e c , $ R e c N u m ) { . . . }

Argument Description

$BlockName Returns the name of the block calling the function (read only).

$CurrRec Returns an associative PHP array containing the current record (read/write ;

don't forget the & in the function header).If you set this variable to False, it ends the merging like it was the end of therecord set.

$RecNum Returns the number of the current record (read only, first record is number 1).

Examples:

f u n c t i o n f _ a d d _ c o l u m n ( $ B l o c k N a m e , & $ C u r r R e c , $ R e c N u m ) {

$ C u r r R e c [ ' l e n ' ] = s t r l e n ( $ C u r r R e c [ ' t e x t ' ] ) ;

}

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 ifits condition is verified.Supported operators are:

= or == equal

!= not equal

+- greater than

+=- greater than or equal to

-+ less than

-=+ less than or equal to

~=expr1 match the regular expression expr2 (for experimented users) Versioning: added in TBS 3.0

Both expr1 and expr2 must be string or numerical expressions. The expressions may contain[var] fields.Example:

<div>[onload;block=div;when [var.x]~='*to*'] ... </div>The <div> block will be displayed only if $x>0.

Note: do not confuse parameter when (which works only for TBS blocs or sections) andparameter if (which works only for TBS fields). Thus, parameter when is taken into accountonly if parameter block exists in the same TBS tag.See conditional blocks for more details.

default Indicates a section of block that must be displayed only if no conditional section of the sameblock has been displayed.

several Indicates that several conditional sections of the block can be displayed if several conditionsare true. By default, conditional sections are exclusive.

Sections of block:

Page 23: TBS Manual

13/02/12 TBS Manual

23/34www.tinybutstrong.com/manual.php#php_mergeblock

Different blocks having the same name will be regarded as sections of the same block.Sections can be used to:- alternate the display (normal sections),- display something if there is no data (NoData section),- display a header each time the value of a column changes (grouping sections).

Normal sections:

When you define several normal sections, they will be used alternatively for each record.

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 greenbackground and with a blue background.

NoData section:

The NoData section is a section displayed only if the data source has no records. There can be only one NoDatasection in a block. The NoData section is defined by adding the parameter nodata.

Example:

[b1.caption;block=tr]

There is nothing. [b1;block=tr;nodata]

Grouping sections:

Grouping sections are displayed every time a column's value in the record-set changes. You can define header,footer, splitter or parent sections using parameters headergrp, footergrp, splittergrp, and parentgrp. See block'sparameters for more details.

Example:

Year: [b1.year;block=tr;headergrp=year]

[b1.caption;block=tr] [b1.amount]

Conditional sections:

Conditional sections are displayed only if their condition is verified. The condition for display is defined usingparameter when. As soon as a section has this parameter, it becomes conditional. See Conditional display for moredetails.

Example:

[b1.name;block=tr]

[b1.address;block=tr;when [b1.add_ok]==1]

Serial display (in columns):

The serial display enables you to display several records inside a block. For this, you have to use a main block andsecondary blocks.

Example:

Rec 1 Rec 2 Rec 3 Rec 4

Rec 5 Rec 6 Rec 7 Rec 8

Rec 9 ... ... ...

In this example, main blocks are the blue lines of the table, the secondary blocks are the pink cells.

Syntax:The main block and its secondary blocks are merged using only one call to the MergeBock() method. The main blockmust be defined using the parameter serial. The secondary blocks must be nested into the main block. Thesecondary block's names must be the name of the main block followed by "_" and a number indicating display order.

Page 24: TBS Manual

13/02/12 TBS Manual

24/34www.tinybutstrong.com/manual.php#php_mergeblock

Example:

[bx;block=tr;serial][bx_1.txt;block=td]

[bx_2.txt;block=td] [bx_3.txt;block=td] [bx_4.txt;block=td]

The corresponding PHP is:

$ T B S - > M e r g e B l o c k ( ' b x ' , $ c n x _ i d , ' S E L E C T t x t F R O M t _ i n f o O R D E R B Y t x t ' )

Empty secondary block:You can specify a special secondary block that will be used to replace unused secondary blocks (without records).This "Empty" secondary block must have the index 0. It can either be placed inside the main block with the normalsecondary block, or alone inside another serial block. The "empty" secondary block is optional.

Example:

[bx;block=tr;serial][bx_1.txt;block=td]

[bx_2.txt;block=td] [bx_3.txt;block=td] [bx_4.txt;block=td]

[bx;block=tr;serial][bx_0;block=td]

No records found.

Remark:The serial display also works with sections of block and dynamic queries.

Subblocks:

A subblock is a TBS block nested into another TBS block and that should be displayed as a separated block for eachrecord of its parent block.

Example:

Parent block record #1

Subblock record #1.1

Subblock record #1.2

Parent block record #2

Subblock record #2.1

Subblock record #2.2

Subblock record #2.3

Parent block record #3

Subblock record #3.1

They are two different ways to perform subblocks with TBS:

- Automatic subblock: (since TBS 3.5.0) it is when the data of the parent block has a column which contains theready-to-merge data for the subblock. Automatic subblocks are activated using parameter sub1 in the parent block,and they are merged automatically during the merge of the parent block. No extra MergeBlock() are needed.See Automatic subblocks for more details.

- Subblock with dynamic query: it is when the data of the subblocks are retrieved using a query which can changefor each record of the parent block. Subblocks with dynamic queries need an extra MergeBlock() to perform themerging with their dynamic query. Parameter p1 is also needed in the subblock definition in order to set the valuesto inject in the dynamic query.See Subblocks with dynamic queries for more details.

Automatic subblocks:

Automatic subblock are supported since TBS version 3.5.0.

You can use automatic subblocks when the data of the parent block has a column which contains the ready-to-merge subdata for the subblock. Set parameter sub1=column in the parent block to define the column which containthe data for the subblock. If you have several subblocks to merge in the same parent block then use parameterssub2, 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 typesare:

Page 25: TBS Manual

13/02/12 TBS Manual

25/34www.tinybutstrong.com/manual.php#php_mergeblock

- a PHP array- an object supported by TBS (natively or with a plug-in) - a text string of values separated by comas (,).

Example:

Name: [body.name;block=tr;sub1=spokenlg]

[body_sub1.val;block=tr]

Corresponding PHP code:

$ T B S - > M e r g e B l o c k ( ' b o d y ' , $ c n x _ i d , ' S E L E C T n a m e , s p o k e n l g F R O M t _ b o d y )

Result of the merge:

Name: Peter

US

FR

Name: Paul

US

Name: Jack

FR

ES

IT

Have the column optional: If you want no error message when the column is omitted in the parent data, then youcan set it optional by using parenthesis. This is working only if the parent data is a PHP array. Optional column issupported since TBS version 3.6.0.

Example:

Name: [body.name;block=tr;sub1=(spokenlg)]

[body_sub1.val;block=tr]

Direct subblocks (which are not saved under a column): If you use parameter sub1 by omitting the column name,then TBS will assume that the data for the subblock are available directly on the current record instead of under acolumn of this record. Direct subblocks are supported since TBS version 3.6.1.

Example of data that can be merged with a direct subblock:$ d a t a = a r r a y ( ) ;

$ d a t a [ ' g r o u p 1 ' ] = a r r a y ( ) ;

$ d a t a [ ' g r o u p 1 ' ] [ ] = a r r a y ( ' i d ' = > 1 , ' n a m e ' = > ' p e t e r ' ) ;

$ d a t a [ ' g r o u p 1 ' ] [ ] = a r r a y ( ' i d ' = > 2 , ' n a m e ' = > ' p a u l ' ) ;$ d a t a [ ' g r o u p 2 ' ] = a r r a y ( ) ;

$ d a t a [ ' g r o u p 2 ' ] [ ] = a r r a y ( ' i d ' = > 3 , ' n a m e ' = > ' j u l e s ' ) ;

$ d a t a [ ' g r o u p 2 ' ] [ ] = a r r a y ( ' i d ' = > 4 , ' n a m e ' = > ' j i m ' ) ;

Example of direct subblock that can be merged with those data:

Group : [body.$;block=tr;sub1]

[body_sub1.name;block=tr]

Subblocks with dynamic queries:

Principles of the dynamic queries:

It is possible to use the MergeBlock() method with a dynamic query.In your template, you have to define a block by adding the parameters p1, p2, p3,... with their values.The query given to the MergeBlock() method has to contain marks such as %p1%, %p2%, %p3%, ... in order towelcome the values of the parameters p1, p2, p3,...

Each section of the block to be merged that contains a parameter p1 will be computed as a separate block for whichthe dynamic query is re-executed. The sections of the block that have no parameter p1 are combined with theprevious section with a parameter p1.

Example:

Country: France

[blk.town;block=tr;p1='france'] [blk.country]

Page 26: TBS Manual

13/02/12 TBS Manual

26/34www.tinybutstrong.com/manual.php#php_mergeblock

Country: USA

[blk.town;block=tr;p1='us'] [blk.country]

Corresponding PHP code:

$ T B S - > M e r g e B l o c k ( ' b l k ' , $ c n x _ i d , " S E L E C T t o w n , c o u n t r y F R O M t _ g e o W H E R E ( c o u n t r y = ' % p 1 % ' ) " )

Result of the merge:

Country: France

Paris france

Toulouse france

Country: USA

Washington us

Boston us

Use with subblocks:

Dynamic queries enable you to easily build a system of a main-block with subblocks. Here is how you can do it:- Create a main block, and then a subblock inside the main block.- Link them by adding to the subblock a parameter p1 whose value is a field from the main block.- At the PHP side, merge the main block first, and then the subblock.

Example:

Country: [main.country;block=tr]

[sub.town;block=tr;p1=[main.cntr_id]]

Corresponding PHP code:

$ T B S - > M e r g e B l o c k ( ' m a i n ' , $ c n x _ i d , ' S E L E C T c o u n t r y , c n t r _ i d F R O M t _ c o u n t r y ' )

$ T B S - > M e r g e B l o c k ( ' s u b ' , $ c n x _ i d , ' S E L E C T t o w n F R O M t _ t o w n W H E R E ( c n t r _ i d = % p 1 % ) ' )

Result of the merge:

Country: France

Paris

Toulouse

Country: Germany

Berlin

Munich

Country: Spain

Madrid

Barcelona

Remarks:- The parameter htmlconv=esc enables you to pass protected string values to the query.- The dynamic queries also work with sections of block and serial display.

Automatic blocks:

Automatic blocks enable you to automatically merge conditional blocks when some events occur.

There are two types of automatic blocks:- [onload] blocks which are merged automatically when the LoadTemplate() method is called.- [onshow] blocks which are merged automatically when the Show() method is called.

Automatic blocks are not merged with data ; that's why they cannot have normal sections (non conditional sections)and linked fields. Automatic blocks can have only conditional sections. Conditions are evaluated only once, and theybe 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

Page 27: TBS Manual

13/02/12 TBS Manual

27/34www.tinybutstrong.com/manual.php#php_mergeblock

[onshow] bloc's names with "_" followed by a sub name.

Example:

[onload_ligth;block=tr;when [var.light]=1] Light is ON.

[onload_ligth;block=tr;when [var.light]=0] Light is OFF.

[onload_ligth;block=tr;default] Light is ?

See Conditional sections for more details.

Subtemplates:

There are two ways to insert subtemplates in your main template.

Primary insertion using parameter file:

This is the best way to simply insert a part contained in another file, like usually done for headers and footers.

The value given to parameter file must be the name of a file existing on the server. You can use an expression with[var] Fields and the [val] keyword which represent the value of the field. If the value is an empty string, then noerror 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 mergedata with a block defined into a subtemplate, then it's suggested to use parameter file in an [onload] field in orderto 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 templateonly the <body> part (or another part). This can be done by adding parameter getbody to parameter file in the TBSfield of the main template. This technique enables you to work WYSIWYG with your subtemplates.

Insertion driven with Php code using parameter subtpl:

Parameter subtpl is useful to manage subtemplate insertion with Php code. Parameter subtpl is active only whenused with a parameter script or onformat. It turns the current TBS instance in Subtemplate mode during the script orfunction execution and can act on a new template without deteriorating the main template.

The Subtemplate mode presents the following characteristics:

* Php outputs are displayed at the field's place instead of being immediately sent to the client. For example, usingthe Php command echo() will insert a text in the main template instead of be directly output it. Using the Show()method will also insert the result of the sub-merge into the main template.

* A reference to the TBS instance is provided by local variable $this or $TBS, whether you use parameter script oronformat. This variable be used for new submerges without deteriorating the main template. The Show() methodwon't stop any script execution during the Subtemplate mode like it does by default in normal mode.

When the script or the function ends, the TBS instance returns in normal mode with the main TBS template.

Example with parameter script:

HTML: [onload.file;script=specialbox.php;subtpl]

PHP script: < ? p h p

e c h o ( ' * H e r e i n c l u d e a s u b t e m p l a t e * ' ) ;

$ t h i s - > L o a d T e m p l a t e ( $ C u r r V a l ) ; $ t h i s - > M e r g e B l o c k ( ' b l k 1 ' , $ G L O B A L S [ ' c o n n _ i d ' ] , ' S E L E C T * F R O M t a b l e 1 ' ) ;

$ t h i s - > S h o w ( ) ;

? >

Remarks: $CurrVal is a local variable provided by TBS when using parameter script ; this variable is a referenceto the value of the field currently merged. In the example above, $CurrVal has the value of the globalvariable $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.

Page 28: TBS Manual

13/02/12 TBS Manual

28/34www.tinybutstrong.com/manual.php#php_mergeblock

Example with parameter onformat:

HTML: [onload.user_mode;onformat=f_user_info;subtpl]

PHP user function: f u n c t i o n f _ u s e r _ i n f o ( $ F i e l d N a m e , & $ C u r r V a l , & $ C u r r P r m , & $ T B S ) {

i f ( $ C u r r V a l = = 1 ) { / / U s e r i s l o g g e d i n

$ T B S - > L o a d T e m p l a t e ( ' u s e r _ i n f o . h t m ' ) ;

$ T B S - > M e r g e B l o c k ( ' b l k 1 ' , $ G L O B A L S [ ' c o n n _ i d ' ] , ' S E L E C T * F R O M t a b l e 1 ' ) ; $ T B S - > S h o w ( ) ;

} e l s e { / / U s e r n o t l o g g e d i n

e c h o ( ' Y o u a r e n o t l o g g e d i n . ' ) ;

}

}

Remarks: $CurrVal is a variable declared as an argument of the function. It's TBS that is in charge to call thisfunction 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 areference to the array of parameters of the field currently merged, and $TBS is a reference to theTinyButStrong instance currently used. See parameter onformat for more information.

Conditional display overview:

TinyButStrong offers several tools for conditional display for both fields and blocks.

Conditional fields

For any TBS fields you can use parameters for conditional display, recalled below.

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 conditionthen value1else value2

Display value1 or value2 depending on whether the condition is verifiedor not.

frm=format1|format2|format3|format4 Changes the numeric format or date/time format depending on whetherthe value is positive, negative, zero or empty.

Example:[onshow.error_id;if [val]=0;then 'no error';else 'error found']

Conditional sections

You can use conditional sections any TBS block (data block or automatic block). A conditional section is a sectionwhich has a parameter when defining a condition, or parameter default. At the block's merging, each when conditionof conditional sections is evaluated until one is verified. As soon as one when condition is verified, its conditionalsection is kept and other conditional sections are deleted. If no when condition is verified, then the default section isdisplayed if it exists.

The case of data blocks:If it is a data block, it means a block merged with MergeBlock(), then the conditional sections are reassessed foreach record. It is even possible to define a data block with only conditional sections, with no standard section.

Defining the conditions:The conditions defined into parameters when can be expressions that contain [var] fields et and linked fields (if it isa data block). See parameter when for more details about operators supported by TBS.

Section exclusivity: By default conditional sections are exclusive inside a block. It means only one conditional section of a block can bedisplayed. But if you want a block to have non-exclusive conditional sections, you can use parameter several on thefirst conditional section. With this parameter, all conditions are evaluated and each true condition makes its sectionto 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:

Page 29: TBS Manual

13/02/12 TBS Manual

29/34www.tinybutstrong.com/manual.php#php_mergeblock

[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.

Page 30: TBS Manual

13/02/12 TBS Manual

30/34www.tinybutstrong.com/manual.php#php_mergeblock

Coding plug-ins:

You can add features to TinyButStrong using plug-ins. The database plug-ins simply enable the method MergeBlock() torecognize new types of database. The other plug-ins enable you to add features to TBS or to modify its main methods inorder 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 expectedby TBS. Some plug-ins are proposed for download at the TinyButStrong web site.

Database plug-ins:

Versioning: database plug-ins are supported since TBS version 1.8.

A database plug-in enables the method MergeBlock() to recognize a new type of database.When you have a call such as $TBS->MergeBlock($BlockName, $Source, $Query), the MergeBlock process is firstexamining $Source to see if its type is supported.

• If $Source is a type of resource known in native by TBS, then the MergeBlock process doesn't need any plug-inhelp, it will retrieve the data by its own.

• If $Source is an object having a method named tbsdb_open() then the MergeBlock process assumes that theobject is a database plug-in and use it to retrieve the data. (See more details below)

• If $Source is a string beginning with '~' then the MergeBlock process assumes that property $TBS->ObjectRef is adatabase plug-in and use it to retrieve the data. (See more details below)

• If $Source is something else then the MergeBlock process is trying to found the plug-in made by user functionsthat correspond to the type of $Source. (See more details below)

Database plug-in based un user functions:

When the MergeBlock process meet a type of value for $Source which is not supported in native, it determines theTBS Id corresponding to that type. Then it looks for the user functions corresponding to that TBS Id.

How to determine the TBS Id:The TBS Id is a string identifier determined by the argument $Source.If $Source is a string => the TBS Id is that string.If $Source is a PHP resource => the TBS Id is the name of the resource's type.If $Source is an object => the TBS Id is the name of the class.For some convenience, if the TBS Id contains spaces (' '), it is cut. If the TBS Id contains '-', they are replaced with '_'.For example, a PHP variable for a Sybase connection is typed as Resource and its resource name is 'sybase-db link'.The corresponding TBS Id is 'sybase_db'.

How to build the plug-in for a TBS Id:The plug-in is made of 3 user functions which must have specific names.The following function names are made for a TBS Id which is 'tbsid'. For another TBS Id, you just have to rename thefunctions.You can found several examples of database plug-in at the TinyButStrong web site.

Synopsis:

function tbsdb_tbsid_open(&$Source, &$Query)

This function is called one time by the MergeBlock process, before the other user functions. It is supposed to use $Source and $Query to open a recordset, and return a reference of that recordset.

function tbsdb_tbsid_fetch(&$Rs [,$RecNum])

This function is called several times by the MergeBlock process, as many times as there are data to fetch fromthe query. This function should return the next record as an associative array (column name=> value), or return false ifthere is no record left.$Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.$RecNum can be useful for some database type such as Oracle, for which the number of the record is needed toretrieve it.

function tbsdb_tbsid_close(&$Rs)

This function is called on time by the MergeBlock process, after the other user functions. This function should close the recordset properly. $Rs is the value provided by tbsdb_tbsid_open(). It is commonly a recordset's reference.

Database plug-in based on object:

When the MergeBlock process meet of value for $Source which is an object, and if that object has a method namedtbsdb_open(), then it assumes that the object is a database plug-in. The object must have at least the 3 methods tbsdb_open(), tbsdb_fetch() and tbsdb_close(). There can be othermethods and properties, but those 3 methods must have the same syntax and the same feature as the userfunctions described above.

Synopsis:

class clsTbsPlugin {

Page 31: TBS Manual

13/02/12 TBS Manual

31/34www.tinybutstrong.com/manual.php#php_mergeblock

function tbsdb_open(&$Source, &$Query) function tbsdb_fetch(&$Rs [,$RecNum]) function tbsdb_close(&$Rs)}

Database plug-in based on property ObjectRef:

When the MergeBlock process meet a value for $Source which is a string beginning with '~' then it assumes thatproperty $TBS->ObjectRef is a database plug-in based on object (see OOP). The object must have the samerequirements as a database plug-in based on objet described above, but the names of the methods can bedifferent.

Example: $TBS->MergeBlock($BlockName,'~dbkey',$Query);

class clsTbsPlugin { function dbkey_open(&$Source, &$Query) function dbkey_fetch(&$Rs [,$RecNum]) function dbkey_close(&$Rs)}

Other plug-ins:

Versioning: plug-ins are supported since TBS version 3.0.

Coding a plug-in using a PHP class:

• Plug-in's key:

Each plug-in has a plug-in key which is the name of its Php class. This key must be given to the method PlugIn()when you use it. Thus, it is recommended to define a PHP constant for the plug-in's key (see example below).

• Plug-in events:

A TBS plug-in must be a PHP class which contains one or several specific methods that will be recognized andplugged by TBS. Those specific methods are called plug-in events because they are executed automatically by TBSwhen the corresponding event occurs. A TBS plug-in can also have other methods and properties for internalpurpose. A TBS plug-in must have at least the OnInstall event.

For example:

/ / T B S p l u g - i n X X X

d e f i n e ( ' T B S _ X X X ' , ' c l s T b s P l u g I n g _ X X X ' ) ; / / T h a t i s t h e p l u g - i n ' s k e y c l a s s c l s T b s P l u g I n g _ X X X ( ) {

f u n c t i o n O n I n s t a l l ( . . . ) { . . . } / / T h a t i s t h e O n I n s t a l l e v e n t

. . .

}

See the PHP file "tbs_plugin_syntaxes" to have all plug-in events, their usage and expected arguments. There isalso 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 PHPfile "tbs_plugin_syntaxes"). The OnInstall event is called when the plug-in is installed at the TBS instance.This event can be called in three situations:- When using method PlugIn() with the plug-in's key for the first time.- When using method PlugIn() with the plug-in's key and the argument TBS_INSTALL. - When a new TBS instance is created, if the plug-in's key has be added to the global array$_TBS_AutoInstallPlugIns[] (see file "tbs_plugin_syntaxes.php" for more details).

Property ->TBS:

As soon as the plug-in is installed on the TBS instance, a property - > T B S 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 theplug-in's code.

Coding a plug-in using PHP functions:

The plug-ins' key is a string that you choose and which will be used for naming the function. It is recommended todefine 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'skey, followed by '_' and the event's name. Example:

d e f i n e ( ' T B S _ X X X ' , ' x x x ' ) ;

f u n c t i o n t b s p i _ x x x _ O n I n s t a l l ( . . . ) { . . . }

Page 32: TBS Manual

13/02/12 TBS Manual

32/34www.tinybutstrong.com/manual.php#php_mergeblock

� � �

All the rest works like for plug-in coded with a class. You must have at least the event OnInstall created, and itworks the same way.

Remark: PHP functions are often faster than methods, but they don't let you having a ->TBS property to reach theparent TBS instance.

List of plug-in events:

Plug-in Events Description

• OnInstall Executed automatically when the plug-in is called for the first time, or when PlugIn()method is called with the specific argument for installing.

• OnCommand Executed when PlugIn() method is called. This is a way to execute any user commandspecific 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 toparameter 'ondata' but for every block)

• OnFormat Executed each time a fields is being merged. (similar to parameter 'onformat' but for everyfields)

• 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 TBS3.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 TBS3.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.

Page 33: TBS Manual

13/02/12 TBS Manual

33/34www.tinybutstrong.com/manual.php#php_mergeblock

Summary:

TBS Field's parameters:

Parameter Summary

htmlconv Char conversion Mode for the field's value.

. (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'svalue.

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 tags.

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.

tplfrms Use with onload fields only. Define template formats.

tplvars Use with onload fields only. Define template variables.

protect Protection mode for characters '['.

comm Extends the field's bounds up to the Commentary tag that surround it.

noerr Avoid some TBS error messages.

file Includes the contents of the file.

script Executes the Php script.

getbody Use with file or script. Insert only a part of the subtemplate.

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.

TBS Block's parameters:

Parameter Summary

block Defines the block's bounds.

nodata Indicates the section that is displayed when there is no data in the data source.

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.

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.

Names of Special Fields and Blocks:

Page 34: TBS Manual

13/02/12 TBS Manual

34/34www.tinybutstrong.com/manual.php#php_mergeblock

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 PhpArray.

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.

. : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . : * ~ * : . _ . :