|
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* |
|||||||
|
Template Engine for Pro and Beginners for PHP version 4.2.0 or higher |
Introduction: |
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: |
Some examples: |
$TBS->MergeBlock("Blk","mysql","SELECT * FROM MyTable WHERE id=$id)") ; | + |
|
=> |
|
|||||||||||||||||||||||||||||||||
$TBS->MergeField("MainTitle","A New World") ; | + |
|
=> |
|
|||||||||||||||||||||||||||||||||
$TBS->MergeBlock("lst_type",array("-","Mr","Mme","Mss")) ; | + |
|
=> |
|
|||||||||||||||||||||||||||||||||
$TBS->MergeField("x_type","Mss") ; | + |
|
=> |
|
Basic Principles: |
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 : |
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"); |
Here is the list of properties and methods of a TinyButStrong
object:
CacheAction() method: |
Activates the Cache System or starts
another operation on cache files.
Instead of the time-out, you can use one of the constants below in order to start a special action of the Cache System.
|
GetBlockSource() method: |
Returns the source of the Merge-Block. Syntax: $TBS->GetBlockSource(string BlockName{, boolean List})
This medthod enables you
to get the source of a block in order to manually manage the merging. |
LoadTemplate() method: |
Load a template in order to merge
it with data. Syntax : $TBS->LoadTemplate(string File)
|
MergeBlock() method: |
Merge a Merge-Block and
data from a record source.. Returns the number of records met. TinyButStrong supports several data source types in native: Php data: an array ; a string ; a number. Databases: MySQL ; ODBC ; SQL-Server ; ADODB. You also can code customized functions to read data (see chapter 'custom data source'). There are also already coded functions at the Support page of the TinyButStrong Web site. Syntax : $TBS->MergeBlock(string BlockName, mixed Source{, string Query}{, int PageSize, int PageNum}{, int RecKnown})
Resource and Request arguments according to the data source type:
(2) This is the ADODB data access method from Microsoft, available through the Php COM class. HTML side: The HTML template may contain one, several or no Merge-Blocks corresponding to the specified name.
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.
Record count: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MergeField() method: |
Replace a Merge-Field of the template with a value. Syntax : $TBS->MergeField(string FieldName, mixed Value)
HTML side: |
MergeSpecial() method: |
Replace all the fields and blocks of the specified type. Syntax : $TBS->MergeSpecial(string
Type)
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: |
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: |
Determines how the merge should ends. Syntax: int
$TBS->Render
|
Source property: |
Get or set the HTML source that the
TinyButStrong object is working with to merge. |
Global variables: |
TinyButStrong provides
global variables that you can use for you PHP program. |
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: |
A Merge-Field is a locator which
has to be replaced by a single data item. Syntax: HTML...[FieldName;params]...HTML
Case sensitivity: TinyButStrong is case insensitive in templates, Merge-Field coding included. |
Merge-Blocks: |
A merge-block enables you to display data from a
record source. The merge between the block and the data is proceed using the method MergeBlock(). During the merging, a simple merge-block is repeated as much time as there is record ; and the associated merge-fields are replaced by the value of the columns. An merge-field associated to Block1 and which displays the value of the column ColumnA must be named Block1.ColumnA Example : [Block1.ColumnA;frm='mm-dd-yyyy'] You can define more elaborted merge-blocks using: - Block's parameters, - Mutli-sections blocks (alternated or special), - Sub-blocks (serial display or multi-columns), - Clone blocks (using a parametrized query). Block syntaxs : There are tree possible syntaxs to define a merge-block:
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. Block's parameters :
Multi-sections blocks (alternated or special) : When you define several blocks with the same name, they consitute sections of the block. Sections wich have the parameter nodata or headergrp are special section and they are described above, others are standard sections. If there are several standard sections that fallow each other, then they will be alternated on each record. Example:
The example below shows a multi-section block with two alternated sections green/blue and one 'nodata' special section . You can combine multi-sections with sub-blocs and clone blocks. Sub-blocks (for serial display) : Sub-blocks enable you to display a serie of several records per block. For example, this can be used in order to make a multi-column display. You must indicate that a block contains sub-blocks by setting the parameter serial. Sub-blocks will must be inside the parent block and their name must be the name of the parent block fallowed by '_' and by the serial number (beginning with 1). Empty sub-block: You can define a sub-block which going to be used to replace unused sub-blocks. This 'empty' sub-block has to get the serial number 0. It can be placed in a normal serial block or alone in another serial block. The 'empty' sub-block is optional. Example :
in this example, there is a multi-columns display on tree columns with a definition of an 'empty' cell. You can combine Sub-blocs with multi-sections and Clone blocks. Clone blocks (and parametrized query) : Clone blocks are blocks with the same that will be merged with only one call to the MergeBlock() method. They distinguish themselves from multi-sections by the presence of the parameter p1 at the beginning of a clone block. They can possibly have others p2, p3, parameters but p1 is compulsory. For each clon block, the SQL query string given to the MergeBlock() method is modified using the paremeters of the block. Each keywork '%p1%', '%p2%', '%p3%'... placed inside the SQL query string will be replaced with parameters p1, p2, p3... If the parameters's values are string, then the parameter htmlconv=esc may be useful. Example of a definition of tree clone blocks:
PHP code: $TBS->MergeBlock('blc',$cnx_id,'SELECT ville FROM t_ville WHERE (pays_id=%p1%)') Clone blocks can have multi-sections and sub-blocks. Case sensitivity: TinyButStrong is case insensitive in templates, Merge-Block coding included. |
File inclusion : |
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.
Examples: |
Php variable Fields: |
A Php variable Field id a Merge-Fields
which display a Php variable. Merge-Fields don't need to have the same case as their corresponding
PHP variables. |
System Fields : |
A System Field is a Merge-Field which
presents the proper data to the TinyButStrong
engine.
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: |
Merge-Fields and Merge-Blocks can
contains parameters that allow you to display or hide them conditionaly.
|
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.: