Site : www.tinybutstrong.com
Author : skrol29@freesurf.fr
Date : 2003-04-29

*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*
TinyButStrong
version 1.65
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*

 
Thanks : Mark Davis
Template Engine for Pro and Beginners
for PHP version 4.2.0 or higher
and MySQL / ODBC / SQL-Server / ADODB
 

Help plan:
  Introduction
  Summary of supported features
  Some examples
  Basic principles
  Installation
  PHP side
      CacheAction() method
      GetBlockSource() method
      LoadTemplate() method
      MergeBlock() methode
      MergeField() method
      MergeSpecial() method
      Show() method
      Render property
      Source property
      global variables
  HTML side
      Merge-Fields
      Merge-Blocks
      File inclusion
      Php variable Fields
      System Fields
      Conditional display

 

Introduction:
top


TinyButStrong is a PHP class useful to develop an application cleanly separating PHP scripts and HTML files. With TinyButStrong, HTML pages are generated dynamically by merging a template with data. It is called a Template Engine.

The name TinyButStrong comes from the fact that this tool contains only 7 functions and yet, is very powerful. It allows you to merge HTML pages templates with your PHP variables or your MySQL, ODBC SQL-server or ADODB queries.

TinyButStrong has been engineered so that you can develop your HTML pages templates with ease using any visual HTML editors (like Dreamweaver or Frontpage). But if you are used to designing your HTML pages with a text editor, it is nice as well. TinyButStrong also enables to create JavaScript dynamically.

As its name says, TinyButStrong is easy to use, strong and fast. TinyButStrong is completely °~° freeware °~°.


Summary of supported features:
top
Some examples:
top

$TBS->MergeBlock("Blk","mysql","SELECT * FROM MyTable WHERE id=$id)") ;
 +
First name Last name Date
[Blk.Sign_FirstN] [Blk.Sign_LastN;block=row] [Blk.Sign_Date;frm=mm/dd/yyyy]
[Blk.Sign_FirstN] [Blk.Sign_LastN;block=row] [Blk.Sign_Date;frm=mm/dd/yyyy]
There is no name in the list. [Blk;block=row;nodata]
 =>
First name Last name Date
Petter SMITH 03/01/2002
John BENNET 09/07/2001
Julia DOMINGO 03/01/2002
Paul DEVILLE 08/05/2003
Morgan LOWELL 03/01/2002
Sue SUMMER 12/23/1999
         
$TBS->MergeField("MainTitle","A New World") ;  +

[MainTitle]

 =>

A New World

         
$TBS->MergeBlock("lst_type",array("-","Mr","Mme","Mss")) ; +

=>

         
$TBS->MergeField("x_type","Mss") ; +

=>

 

Basic Principles:
top

On the HTML side: You design a page which does not need to contain any PHP script. In this page you put TinyButStrong locators at the places where data items should display. This page is called 'a Template'.

On the PHP side: You use an object TinyButStrong variable to manage the merge of your HTML Template with the data. At the end, TinyButStrong shows the result of the merge.

There are two types of locators which you can put in your template : merge-field and merge-block. The first one displays a data item, and the other one repeats an area by basing it on a data source.

 

Installation :
top

1. Copy the file tbs_class.php in a directory or the Web site.
2. Reference the source code of TinyButStrong in your PHP program using the 'include_once' instruction ('require_once' is also available).
Example : include_once("tbs_class.php");
3. Declare an object variable as a new instance of the clsTinyButStrong class.
Example : $TBS = new clsTinyButStrong ;

 

PHP side:

Managing the merge of a template is facilitated with a PHP program using an object variable declared as a clsTinyButStrong class.
Example of statement: $TBS = new clsTinyButStrong ;
This object allows you to load a template, to manage its merge with data, and then to show the result.

Example of PHP code:

 

include_once("tbs_class.php");
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate("template.htm") ;
$TBS->MergeBlock("ctry","mysql","SELECT * FROM t_coutry") ;
$TBS->Show() ;

Here is the list of properties and methods of a TinyButStrong object:

CacheAction() method:
top

 

Activates the Cache System or starts another operation on cache files.

Syntax: bool $TBS->CacheAction(string CacheId {, int ActTimeOut}{, string Dir})

The Cache System enables you to speed up the display of HTML pages by proceeding the merge at regular times instead of at each call of the page. For this, you must forsee an unique string identification for each page that should be saved (we call it 'cache file'), and also a refresh period (we call it time-out). We you call the CacheAction() method the System will look for an existing cache file and get its creation time. If the creation time is shorter than the time-out then the content of the cache file is loaded and the merge ends. If the creation time is longer than the time-out then the cache file is ignored but it will be updated at the next call of the Show() method by saving the result of the merge in this cache file.

If the cache file is loaded then the method returns True, otherwise it returns False.
By default, if the file is loaded then the content is displayed and the script is ended but you can change this behavior using the Render property.

Element Description
CacheId A string wich identifies in a unique way your page in the cache directory.
ActTimeOut Must be the time-out expressed in seconds or one of the constants below.
The default value is 3600, wich means one hour.
Dir Optional. The path of the directory where the cache file is saved.
by default, it is the same directory as the script.

Instead of the time-out, you can use one of the constants below in order to start a special action of the Cache System.

Constant Description
TBS_DELETE Delete the cache file. If the parameter CacheId is set to the keyword "*" then all cache files of the directory are deleted.
TBS_CANCEL Cancel the update of the cache file if it was supposed to be updated at the end of the merge.
TBS_CACHENOW Save the current result of the merge in the cache file.

GetBlockSource() method:
top

 

Returns the source of the Merge-Block.
Only the first definition of the block will be returned except if the List parameter is set to True.
If no block is found, the method returns False.

Syntax: $TBS->GetBlockSource(string BlockName{, boolean List})

Élément Description
BlockName The name of the block to search for.
List Optional. The default value is False.
If this parameter is set True the method returns an array that contains all the definitions of the named block.
The first definition is returned into the item [1] of the array.

This medthod enables you to get the source of a block in order to manually manage the merging.
After that, if you need to replace the block with text, you can use the MergeBlock() method with the "text" parameter .


LoadTemplate() method:
top

 

Load a template in order to merge it with data.
The source of the file is recorded in the Source property of the TinyButStrong object.

Syntax : $TBS->LoadTemplate(string File)

Element Description
File local or absolute URL of the file to load.

MergeBlock() method:
top

 

Repeat a Merge-Block as many times as there are records in the specified data source.
The Merge-Fields linked to this block are replaced with the values of the data source.

TinyButStrong supports several data source types:
MySQL queries, ODBC queries, SQL-Server queries and ADODB queries. A PHP array, a text or a number.

Syntax : $TBS->MergeBlock(string BlockName, mixed Resource{, string Query}{, int PageSize, int PageNum}{, int RecKnown})

Element Description
BlockName Indicates the name of the Merge-Block to merge.
Resource

Indicates the data source to merge.
The table below shows the possible arguments corresponding to the data source type.

Query Optional. Indicates the SQL statement which returns the data to merge.
The table below shows when to use this argument according to the data source type.
PageSize Optional. This parameter must be defined in order to activate the display by page.
Indicates the number of record for one page.
PageNum Optional. This parameter must be defined in order to activate the display by page.
Indicate the number of the page to display. The first page is number 1.
RecKnown Optional. The default value is 0.
This parameter is useful only with the display by page. It indicates the total number of records known. If you set this parameter to a positive or zero value, then the method returns this same value or the number of visted records if it is higher. If you set this parameter to the value -1, then the method returns the total number of records in the data source even over the asked page.

Resource and Request arguments according to the data source type:

Data Source Type
Resource
Query
Text the keyword "text" The text
Number the keyword "num" A number
PHP Array A PHP array with keys and values -
A PHP array that contains arrays with keys and values -
MySQL A connection id
or the keyword "mysql"
A SQL statement
A result id -
ODBC A connection id A SQL statement
A result id -
SQL-Server A connection id
or the keyword "mssql"
A SQL statement
A result id -
ADODB A connection object A SQL statement
A recordset object -

Warning : I personally met problems of accents using the SQL-Server functions for PHP.

HTML side:

The HTML template may contain one, several or no Merge-Blocks corresponding to the specified name.

If only one Merge-Block is found:
  The Merge-Block is repeated as many times as there are records in the data source.
The Merge-Fields placed inside the Merge-Block can be linked with their name.
Each Merge-Field linked is replaced with the corresponding value from the current record.
Example : block name: Block1, columns returned by the query : Field1,Field2,Field3, possible linked Merge-Fields: [block1.field1], [block1.field2], [block1.field3]
(see below for merging with a PHP Array variable)

If serveral Merge-Blocks are found:
  The principle is the same that for the merge with a single block, but TinyButStrong will change the block at each record so as to alternate the display presentation. This enables you, for example, to change the color a line or two in a table. See examples.

If no Merge-Block is found:
  The linked Merge-Fields are all the same. There is no block multiplication and only the first record of the data source is merged.
In other words, if you have only one record, the block definition is optional.

Merge with text :
The entire block is replaced with the specified text. Column names are ignored except "#" which represents the number of records, this will always be 1 or 0 if the text is an empty string.

Merge with number :
The block is repeated as much time as the given number. Column names are ignored except "#" which represents the number of records.

Merge with a PHP Array variable :
Use the column name "val" in order to display the value of the item, and the column name "key" for the key of the item (PHP enables to affect a key to a value of an array).
  Example : block name: Block1, possible Merge-Fields: [block1.val], [block1.key]
See other example.
If your Array variable contains Arrays, then it is different. The merge operates like it was a record set: each sub-array is considered as a record and their keys are considered as the column's names.

Record count:
In order to display the record number, you can use a Merge-Field with the column name "#".
If is placed outside the block, the it will display the total count of records.
Example : [block1.#]

Case when there is no record to merge:

It is possible to define an extra Merge-Block that will be shown in place of the others when there is no record in the data source. For more information, please refer to the Merge-Block definition .

   

MergeField() method:
top

 

Replace a Merge-Field of the template with a value.

Syntax : $TBS->MergeField(string FieldName, mixed Value)

Element Description
FieldName The name of the field. For example "Title".
Value The value to display.

HTML side:
If several Merge-Fields have the same name in the template, they will be all replaced.
In the Merge-Field definition, you can specify a display format for numeric or date/time values.
It is also possible to force (or prevent) the conversion of the value to HTML. For more information, please refer to the Merge-Field chapter.

Management of HTML lists:
TinyButStrong allows you to select a value in an HTML list. For more information, please refer to the Merge-Field chapter. You can also feed an HTML list with the content of a PHP array or a query using the MergeBlock() method.


MergeSpecial() method:
top

 

Replace all the fields and blocks of the specified type.

Syntax : $TBS->MergeSpecial(string Type)

The Type parameter must be one of the fallowing values:

Value Description
"var" Replace all the Php variable fields.
"sys" Replace all the System fields.
"include"

Replace all the fields and blocks wich are file inclusion and are named tbs_include.

"check" Replace all the fields and blocks wich have conditional display and are named tbs_check.

Remark : by default, the Show() method replace all the special fields and blocks just before to show the merge result. That's why it is rare to use MergeSpecial() in a program


Show() method:
top

 

Terminate the merge.

Syntax: $TBS->Show()

In order to terminate the merge, TinyButStrong proceed to System Fields merging, Php variable Fields merging and others oprations. By default, the result is displayed and the script is ended but you can change this behavior using the Render property.

Render property:
top

 

Determines how the merge should ends.
Its value must be a combination of the constants below.
By default, its value is (TBS_OUTPUT + TBS_EXIT).

Syntax: int $TBS->Render

The Render property changes the behavior the methods Show() and CacheAction().

Constant Description
TBS_NOTHING Indicates that none of the actions below is proceed at the end of the merge ending.
TBS_OUTPUT Indicates that the result of the merge must be display. (use the PHP command Echo)
TBS_EXIT Indicates that the we ahve to quit the script just after the end of the merge.

Source property:
top

 

Get or set the HTML source that the TinyButStrong object is working with to merge.
After the call to the LoadTemplate() method, this property contains the HTML source of the template.
According to the operations of the merge, this property enables you to get or change the intermediate result.

Syntax : string $TBS->Source


Global variables:
haut

 

TinyButStrong provides global variables that you can use for you PHP program.

$tbs_CurrVal represents the current value during the merge of a field.
$tbs_CurrRec represents the current record during the merge of a block.

Those global variables can be used during:
- The merge of a block for whom a custom event function onformat has been definied.
- The merge of a field   for whom a custom event function onformat has been definied.
- The execution of a PHP script with the script parameter.

 

HTML side:

You design your template by placing TinyButStrong locators in the places where data items should appear.

There are two types of locators : Merge-Fields and Merge-Blocks.

A Merge-Field is a locator which has to be replaced by a single data item. It is possible to specify a display format and also other parameters. The syntax for Merge-Fields is describe below.

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

Merge-Fields:
top

 

A Merge-Field is a locator which has to be replaced by a single data item.
It has a name which enables you to identify it and parameters can be supplied in order to change the display behavior.
The definition of a Merge-Field is case insensitive.

Syntax: HTML...[FieldName{;prm1{=val1}}{;prm2{=val2}}...]...HTML

Element Description
NomChamp It is the Merge-Field's name.
Warning : names that begin with sys., var. and tbs_check. are reserved. They are respectively used for System Fields, PHP variables, and Conditional Fields.
prm1 Optional. Has to be a parameter from the list below.
Some paremeters can be affected to a vlaue using the equal sign "=".
Example : frm=0.00
If the value contains spaces or semicolons, you can use simple quotes.
For example : frm='0 000.00'.
It is possible to embed Merge-Fields.

Parameter Description
frm=format

Specify a display format for a data item which is numeric or date/hour. The format is a string built by keywords that will be replaced with their value.

Date/hour Format:
It is VisualBasic like. The following keywords are recognized :
- d, dd, ddd, dddd : number of the day, number of the day with two digits, short name of the day, full name of the day.
- m, mm, mmm, mmmm : number of the month, number of the month with two digits, short name of the month, full name of the month.
- yy, yyyy : year with two digits, year with four digits.
- hh, nn, ss : hours, minutes, seconds with two digits.

Example 1 : [myfield;frm=mm/dd/yyyy] will display 12/21/2002.
Example 2 : [myfield;frm='yyyy-mm-dd hh:nn:ss'] will display 2002-12-21 15:45:03.
Simple quotes are necessary because of the space.

Numeric Format:
It is a string which possibly contains a decimal separator, possibly a thousand separator. Numbers are replaced with representative zeros.

Example 1 : [myfield;frm=0.0000] will display 32456.1415.
Example 2 : [myfield;frm='000 000,00'] will display 32 456,14.
Simple quotes are necessary because of the space.

max=val Indicates the maximum number of characters to display. Beyond this limit, the data item is cut and an ellipsis (...) is added at the bottom.
htmlconv=val Enables you to force or prevent the conversion of the data item to HTML text.
The value val can be one of the following keywords:
  yes : (default value) force the conversion to HTML with new lines.
  nobr : force the conversion to HTML but new lines (useful for <pre> tags for example).
  no : prevent from the conversion to HTML. Usefull to modify Javascript code or modifiy the HTML source.
  look : convert the data item to HTML only if no HTML entities are found inside the data item.
. (dot) If the data item is empty, then an unbreakable space is displayed. Usefull for cells in tables.
ifempty=val If the data item is empty, then it is replaced with the specified value.
friend=tag_name If the data item is empty, then both opening and closing tag_name Html tags wich embeds the merge-field are deleted. Use friendb in order to delete only the tag_name tag wich is before the merge-field. Use frienda in order to delete only the tag_name tag wich is after the merge-field.
Example: friendb=br if the data item is empty, the break line placed before is deleted.
selected This parameter enables you to select a value for an HTML list (inside a form).
The Merge-Field has to be placed within the list values. When the merge executes, this Merge-Field will be replaced with the data item as the selected item of the HTML list. If the value doesn't already exist in the list then it will be added. (see examples)
comm This parameter enables you to widen the bounds of the indicator up to the bounds of the commentary tag (HTML) which embed it.
<!-- [myfield;comm] this is an example--> est stricly identical to [myfield]
This is particulary usefull for designing the template when using a visual HTML editor (such as Dreamweaver or FrontPage).
file=filename Replace the field with the content of the file. Filename can be a string or an expression built with Php variable Fields that returns the file path.
It is also possible to specify a file that is included automaticaly. For more information, please refere to the file inclusion chapter.
script=filename Execute the script just before to replace the locator. TinyButStrong gives a global variable $tbs_CurrVal that contains the text which will be displayed at the place of the locator. This variable can be used and modified with the executed script.
Filename can be a string or an expression built with Php variable Fields that returns the file path.
If the script parameter is used with the if parameter having a NOT verified condition, then the script execution is canceled.
once Must be used with the script parameter. Cancel the script execution if it has previously been called.
if expr1=expr2 Display the data item only if the condition is verified.
If expr1 and expr2 are a same string (not case sensitive), then the data item is displayed. Otherwise, the field is deleted. You can use != insteade of = in order to specifiy an 'not equal' condition. You can use the keyword [val] inside the expressions to represente the data item.
The expressions may contain Merge-Fields. If so, then you may verify that the embeded Merge-Fields are merged before the ones that contain them.
then val1 If the if parameter is definied and its condition is verified, then the data item is replaced with val1.
You can use the keyword [val] inside the expression to represente the data item.
else val2 If the if parameter is definied and its condition is not verified, then the data item is replaced with val2.
You can use the keyword [val] inside the expression to represente the data item.
onformat=fct_name

Enables you to define an PHP event function which is executed just before the merge of the field.
fct_name must be the name of an existing PHP user function with the following syntax:
  function nom_fct($FieldName,&$CurrVal) { ... }
$FieldName is the name of the current field.
$CurrRec is the current value.
The symbol & which is placed before the name of the variable in the declaration of the function has to be preserved in order to get this argument passed by refrence.
Warning: if you modify this value it will change the current merge result.

protect=val Enbales you to protect or not the data item to merge by replacing the characters '[' with they corresponding Html code '&#91;'. The value val can be one of the following keywords:
  yes : (default value) data item is protected.
  no : data item is not protected.
By default, all data merged with a template are protected except if it's a file inclusion. It is strongly recommanded to protect data when it comes from free enter like on a forum for example.

Case sensitivity:
TinyButStrong is case insensitive in templates, Merge-Field coding included.

Merge-Blocks:
top

 

A Merge-Block is an area which has to be repeated. It is defined using one or two locators.
It is possible to set parameters that modify the display behavior .
The MergeBlock() can be used to merge it with a data source.

There are three possible syntaxs to define a Merge-Block:

Absolute Syntax: HTML...[BlockName;block=begin{;prm}]...HTML...[BlockName;block=end].. HTML
   
Relative Syntax: HTML ...<tag_name...>... [BlockName;block=tag_name{;prm }] ...</tag_name...>...HTML
   
Simplified Syntax: HTML ...<tag_name...>... [BlockName.FieldName;block=tag_name{;prm }] ...</tag_name...>...HTML

Element Description
BlockName The name of the Merge-Block.
block=begin Indicates the beginning of the block.
block=end

Indicates the end of the block.

block= tag_name

Indicates a block which is between the opening tag <tag_name...> and the closing tag </tag_nam...> that are embeding the indicator. The opening tag and the closing tag are part of the block.
- row can be used as an alias in order to indicate the row of a table.
  block=row is the same as block=tr.
- opt can be used as an alias in order to indicate the item of an HTML list.
  block=opt is the same as block=option.

prm Optional. Has to be the name of a parameter in the list below.

Parameters Description
nodata Indicates the block which displays only if there is no data to merge.
Reminder: You can define several blocks with the same name. Merge-Blocks with the same name can be used to toggle the data displayed.

Example:

[block1.field1;block=row] [bloc1.field2]
[block1;block=row;nodata]There is no data.
headergrp=colname Indicate a block which displays as header on each change of the colname column.
colname
must be a valide column name returned by the data source.
You can define several headergrp blocks with different columns.
encaps=num Indicates encapsulation level of the indicator by report to the tags specified with the parameter block. The default value is 1.

Example:

[bloc1.field1;block=row;encaps=2] [bloc1.field2]

In the example above, the blue row will be duplicated at the merging because there is 'encaps=2'.
If 'encaps=1' is set or if the parameter is get off, then the rose row will be duplicated at the merging.
comm This parameter enables to widen the bounds of the indicator up to the bounds of the commentary tag (HTML) which embed it.
<!-- [block1;block=row;comm] this is an example--> est stricly identical to [block1;block=row]
This is particulary usefull for designing the template when using a visual HTML editor (such as Dreamweaver or FrontPage).
onformat=fct_name

Enables you to define an event function on the block formating.
The function will be executed before the merge of each detail section of the block.
fct_name must be the name of an existing PHP user function with the following syntax:
  function nom_fct($BlockName,&$CurrRec,&$DetailSrc,$RecNum) { ... }
$BlockName is the name of the current block.
$CurrRec is the current record. It is an array with keys.
$DetailSrc is the source of the current section before it is merged with the current record.
$RecNum is the number ofthe current record.
The symbol & which is placed before the name of the variables in the declaration of the function has to be preserved in order to get those arguments passed by refrence. Warning: if you modify those values it will change the current merge result. For example, if you code $CurrRec = False ; this will stop the block merging. If you code $DetailSrc = '' ; this will cancel the merge only for the current record.

if expr1=expr2 Display the block only if the condition is verified.
If expr1 and expr2 are a same string (not case sensitive), then the data item is displayed. Otherwise, the field is deleted. You can use != insteade of = in order to specifiy an 'not equal' condition.
The expressions may contain Merge-Fields. If so, then you may verify that the embeded Merge-Fields are merged before the ones that contain them.
else Indicates a conditional block displayed only if no other condition of the Merge-Block with same name are verified.
serial Indicates that the block contains a serie of sub-blocks. Instead of merging one record for one block, TinyButStrong will merge one record for one sub-block. The sub-blocks must be contains in the main block and their name must be the same as the main block fallowed by '_' and the serial number (the first is 1).

Example:

[bx.;block=row;serial][bx_1.field1;block=td] [bx_2.field1;block=td] [bx_3.field1;block=td]

In the example above, each cell of the table will contain a record. The row of the table will be duplicated each tree records. This example enables to display the data on several columns.

Which syntax to use?

The Absolute Syntax is rarely used with visual editors because its locators often has to be placed between two HTML tags. on the other hand, it is conveniant for texual editors.

The Relative Syntax enables to indicate a block using only one locator. Furthermore, there is no need to hide the locator because it will be deleted during the displaying. This syntax is quite practical.

The Simplified Syntax is realy simple. It enables to define a Merge-Block and Merge-Field with only one locator. This syntax is the most current and the most practical.

Management of the alernated display
In order to alternate the presentation of a block (for example : change the back color of a row or two in a table) you just have to define several Merge-Blocks, one after the other, with a different look. During the merging process, TinyButStrong will change the block look for each record. See examples.

Case sensitivity:
TinyButStrong is case insensitive in templates, Merge-Block coding included.

File inclusion :
top

 
You have the possibility to include the content of another file at the place(s) you want in your template.
  In order to define a file to include just after the template loading, use a Merge-Field named tbs_include.onload.
  in order to define a file to include just before the result showing, use a Merge-Field named tbs_include.onshow.
  In order to define a file to include at a specific moment in your PHP program, use a Merge-Field with another name and call the MergeField() method to process it.

The file to be include is definied with the file parameter in the Merge-Field. The value of this parameter can be an expression which uses Php variable Fields.
.
Syntax: HTML ...[fieldname;file=filename{;script=filename{;once{;htmlconv=val}}}]...HTML

Parameter Description
file=filename filename is the path for the file to include.
It can be an expression which uses Merge-Fields of PHP variables (prefixed 'var.')
script=filename Execute the script just before to replace the locator. TinyButStrong gives a global variable $tbs_CurrVal that contains the text which will be displayed at the place of the locator. This variable can be used and modified with the executed script.
Filename can be a string or an expression built with Php variable Fields that returns the file path.
If the script parameter is used with the if parameter in a non verified condition, then the script execution is canceled.
once Must be used with the script parameter. Cancel the script execution if it has been previously called.
htmlconv=val Enables to force or prevent from the conversion of the file content to an HTML text.
The value val can be one of the following keywords:
  yes : force the conversion to HTML.
  no : prevent conversion to HTML.
  look : convert the file content to HTML only if no HTML entities are found inside.

Examples:
[tbs_include.onload;file='frame_left.htm'] : file included just after the template loading.
[tbs_include.onload;file=[var.myfile]] : file included just after the template loading.
[tbs_include.onshow;file=[var.myfile]] : file included just before the result showing.

HTML page inclusion:

When the page to be included is an HTML page, TinyButStrong will keep only the source that is between the tags <BODY> and </BODY>.
This feature enables you to include a file as an independant HTML page.


Php variable Fields:
top

 

A Php variable Field id a Merge-Fields wich display a Php variable.
Its name must be composed by the keyword 'var.' fallowed by the name of the Php variable.
The parameters for standard Merge-Fields are available for Php variable Fields.

For example [var.php_version] will be replaced by "4.2.3".

Merge-Fields don't need to have the same case as their corresponding PHP variables.
The user variables and the predefined variables can be merged but only they must be global variables. Object or Resource variables are ignored.

It is possible to merge an Array variable by indicating the item with a dot.
For example: [var.myarray.item]

When are Php variable Fields merged?

Php variable Fields are merged in the Show() method, this means just before the display of the merge result. But you can force the merge at any time with the MergeSpecial() method.


System Fields :
top

 

A System Field is a Merge-Field which presents the proper data to the TinyButStrong engine.
The name of a System-Field has to be one in the list below.
The parameters for standard Merge-Fields are available for System-Fields.

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

Name Description
sys.now Date and hour of the server.
sys.version The TinyButStrong version.
sys.script_name The name of the PHP file currently executing.
sys.template_name The name of the last loaded template file.
It is the name given to the LoadTemplate() method.
sys.template_date The creation date of the last loaded template file.
sys.template_path The directory of the last loaded template file.
It is the directory given to the LoadTemplate() method.
sys.merge_time The duration of the merging process, in secondes with 8 decimals.
sys.script_time The duration of the programm process, in secondes with 8 decimals.
(since the call of the 'include_once' command that loads TinyButStrong)

When are System Fields merged?
System-Fields are merged in the Show() method, this means just before the display of the merge result. But you can force the merge at any time with the MergeSpecial() method.

Conditional display:
top

 

Merge-Fields and Merge-Blocks can contains parameters that allow you to display or hide them conditionaly.
The syntax for conditional display is detailed in chapters Merge-Field and Merge-Block.

Display one block among several blocks:


If you define several blocks wiht the same name, then only one will be displayed. The one that will be displayed is the first in which the condition is verified ; the others will be deleted.
You can also use the parameter 'else' to define a block that will be displayed only if other conditions are false.

To automate the conditional fields and block merging:

When the name of your field or block is prefixed with 'tbs_check.' then it can be automatically merged with the Show() method.
Fields can be named 'tbs_check' without suffix.

If you give some name to your field or block then it won't be automatically merged and you will need to call the MergeField() or MergeBlock() method at the wanted moment in your program.

Examples of conditional fields:

ex1 :
[var.morning;if [val]=1;then 'good morning';else 'good evening']
  is identical to
[tbs_check;if [var.morning]=1;then 'good morning';else 'good evening']

ex2 : href="bouton_[var.light;if [val]=1;then 'on';else 'off'].gif"

Examples of conditional blocks:

[tbs_check.set1;block=row;if [var.light]=1]
This line is displayed if the variable $light value is 1.
[tbs_check.set1;block=row;if [var.light]=0]
This line is displayed if the variable $light value is 0.
[tbs_check.set1;block=row;else]
This line is displayed in other cases.


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