|
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* TinyButStrong Version 2.05 *.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* |
|||||||
|
Was ist neu in der Version (Hervorhebung aktivieren): |
Template Engine für Profis und Anfänger (übersetzt von Claus van Beek) für PHP Version 4.0.6 oder höher |
| Inhalt | Beschreibung |
| • Einleitung | Anmerkung von CVB: Obwohl das Wort "merge" im Deutschen mit "fusioniert", "zusammenfügen" oder "verbinden" übersetzt wird, ist hier das Wort "zuweisen" gemeint. Das Wort "field" wird nicht nur immer mit "Feld" übersetzt, sondern auch mit "Variable", wobei im Regelfall dann eine Templatevariable gemeint ist (siehe "TBS Felder"). |
| Grundprinzipien | |
| Installation | |
| Mini Beispiele | |
| • PHP Teil | |
| • Für den Anfang | |
| Methode LoadTemplate() | lädt die Inhalte eines Templates aus einer Datei |
| Methode MergeBlock() | die Daten aus dem PHP-Skript werden dem Template-Block zugewiesen |
| Methode Show() | parsed das ganze Template und zeigt es an |
| • Für Fortgeschrittene | |
| Methode CacheAction() | aktiviert das Cache System |
| Methode GetBlockSource() | gibt den Quelletext von der Definition eines Blockes zurück. |
| Methode MergeField() | verbindet ein spezifisches Feld mit einem Wert. |
| Methode MergeNavigationBar() | zeigt eine Navigationsleiste an, wobei TBS Blöcke und TBS Variablen benutzt werden. |
| Methode MergeSpecial() | ersetzt speziale Blöcke und TBS-Tags vom spezifiziertem Typ. |
| Eigenschaft Render | nachdem das Template (mit "Show()") geparst und ausgegeben wurde, wird das Skript normalerweise mit "exit;" beendet. Mit der Eigenschaft "Render" kann dieses Verhalten verändert werden. |
| Eigenschaft Source | gibt den Inhalt des Ergibnisses (englisch: result) zurück. |
| Eigenschaft TplVars | gibt die Templatevariabeln zurück |
| Einen RDBMS-Typen hinzufügen | um beispielsweise mit Oracle, MS-SQL oder Informix zu arbeiten. |
| Objekt Orientierte Programmierung (OOP) | um TBS OOP freundlich zu machen |
| • HTML Teil | |
| • TBS Felder | Anmerkung von CVB: Das Wort "field" kann auch mit "Template Tags" oder "Templatevariablen" übersetzt werden, aber "TBS Felder" können mit viel mehr Eigenschaften ausgestattet werden, als dieses bei anderen Template Engines der Fall ist. |
| Definition und Syntax | |
| Parameter | |
| Var-Felder / Templatevariablen | |
| spezielle Felder / Templatevariablen | |
| • TBS Blöcke | |
| Definition und Syntax | |
| Parameter | |
| Sektionen eines Blockes | |
| Blöcke und der Parameter "serial" | |
| Dynamische SQL-Abfragen / Sub-Blöcke | |
| Eine Navigationleiste anzeigen | |
| • Verschiedenes | |
| Automatische Felder und Blöcke | |
| andere Templates inkludieren | |
| Das Resultat eines anderen PHP-Skriptes inkludieren | |
| Parameterabhängige Anzeige-Optionen | |
| • Zusammenfassung | |
| Parameter für TBS-Felder | |
| Parameter für TBS-Blöcke | |
| TBS-Felder und Parameter für Navigationsleisten | |
| Namen von speziellen Feldern und Blöcken |
TinyButStrong (TBS) ist eine PHP-Klasse, die PHP- und HTML-Code (PHP-Skripte und HTML-Dateien sogenannten "Templates") von einander trennt. Damit können Applikationen sauberer entwickelt werden. Mit TBS werden die HTML-Seiten dynamisch erzeugt. Templatevariablen, die Schnittstellen zwischen Template und PHP-Skript, werden mit Inhalten gefüllt. Das nennt man eine "Template Engine".
Der Name "TBS" (TinyButStrong) ist aus der Tatsache entstanden, dass diese Klasse bis jetzt nur 8 Methoden hat und doch ist dieses Tool sehr leistungsstark. Es erlaubt Ihnen globale PHP-Variablen im Template zu verwenden und eine SELECT-Abfrage direkt in einem TBS-Block zu verwenden. TBS unterstützt die RDBMS MySQL, PostgreSQL und SQLite. Weitere RDBMS können zusätzlich eingebunden werden.
TBS wurde entwickelt um HTML Templates mit WYSIWYG-Editoren (wie Dreamweaver oder Frontpage) zu erstellen. Im Gegensatz zu anderen Templateklassen ist TBS vollständig WYSIWYG tauglich. Auch wenn Ihr HTML-Seiten mit einem Texteditor entwickelt, ist die Trennung von PHP und HTML äußerst hilfreich. TBS ermöglicht es ebenfalls JavaScript dynamisch zu erstellen.
Wie der Name schon sagt, ist TBS einfach in der Benutzung, leistungsstark und schnell. TBS ist °~° freeware °~°.
Der HTML Teil:
Um die Vorteile von TBS wirklich zu nutzen, muss man nicht zuerst PHP programmieren, sondern erst das Design seiner Seite bestimmen. Ob dies mit Frontpage oder einem Text-Editor geschieht ist egal. Wichtig ist nur, dass PHP- und HTML-Code von einander getrennt werden. Dazu fügt man TBS-Tags in seine Webseite ein und zwar überall dort, wo man die (dynamischen) Daten plazieren möchte. Diese HTML-Seite heißt dann Template.
Es gibt zwei Arten von Tags:
Der PHP Teil:
Von der Templateklasse wird eine Instanz gebildet (beispielsweise $TBS) und danach können alle Blöcke und Felder mit Inhalten befüllt werden. Dieses geschieht mit den Methoden der Klasse. Am Ende wird über die Methode "Show" das Resultat der Zuweisungen angezeigt.
| 1. | Kopiert die Datei tbs_class.php in ein Verzeichnis auf Eurer Webseite. |
| 2. | Am Anfang des Programmes muss eingegeben werden: include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; Anmerkung: Wenn die Datei "tbs_class.php" in einem anderen Verzeichnis ist, als Eure PHP-Applikation, dann muss das genaue Verzeichnis mit relativem oder absolutem Pfad angegeben werden. |
Erklärungen und technische Details:
TinyButStrong ist eine Klasse die in PHP geschrieben wurde. Sie kann in Euren eigenen PHP-Skripten verwendet werden. TinyButStrong ist eine PHP-Klasse, von der beliebig viele Instanzen abgeleitet werden können (siehe oben). Der Name der Klasse ist "clsTinyButStrong".
Die Instanz "$TBS" die am Anfang des PHP-Skriptes abgeleitet wird, stellt dann mit seinen Methoden die Technik des Templating zur Verfügung. Diese Methoden erlauben es dann TBS-Felder und -Blöcke mit Inhalten zu füllen.
| HTML Template | PHP-Skript | Ausgabe |
| <html> <body> [var.message] </body> </html> |
<?php include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; $TBS->LoadTemplate('template.htm') ; $message = 'Hello' ; $TBS->Show() ; ?> |
<html> <body> Hello </body> </html> |
| HTML Template | PHP-Skript | Ausgabe |
| <table> <tr><td>[blk.val;block=tr]</td></tr> </table> |
<?php include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; $TBS->LoadTemplate('template.htm') ; $list = array('X','Y','Z') ; $TBS->MergeBlock('blk',$list) ; $TBS->Show() ; ?> |
<table> <tr><td>X</td></tr> <tr><td>Y</td></tr> <tr><td>Z</td></tr> </table> |
Die Zuweisung von Blöcken und TBS-Variablen bzw. Feldern wird im PHP-Skript gemacht. Dazu benutzt man eine Instanz, die man von der Klasse clsTinyButStrong abgeleitet hat. Beispiel: $TBS
= new clsTinyButStrong;
Diese Instanz erlaubt uns, dass Template zu laden, die Daten zu verarbeiten und das Ergebnis anzeigen zu lassen. TBS spricht hier von "to merge" etwas zusammenfügen.
Der komplette Dateiinhalt ist in der Eigenschaft Source (deutsch: Quelle) des TBS-Objektes gespeichert.
Syntax:
$TBS->LoadTemplate(string File{, string HtmlCharSet})| Argument | Beschreibung |
| File | die Datei muss mit relativem oder absolutem Pfad angegeben werden. |
| HtmlCharSet |
Optional. Gibt an, welche Zeichenkodierung (charset) benutzt werden soll, sobald die Daten dem Template übergeben ("gemerged") werden. Der übergebene Parameter sollte identisch mit der Zeichenkodierung des Templates sein. Der Default Wert ist '' (leerer String); ein Äquivalent zu 'ISO-8859-1' (Latin 1). Wenn Ihr in Eurem Template eine spezielle Zeichenkodierung verwendet, dann müsst Ihr diesen Parameter an dieser Stelle übergeben. |
Keine Konvertierung von HTML Sonderzeichen:
Im Normalfall werden alle HTML Sonderzeichen von TBS konvertiert ("gequotet", "escaped"). Man kann der Methode den Parameter HtmlCharSet den Wert false (oder auch großgeschrieben FALSE) übergeben. Dadurch werden alle HTML-Tags in der Ausgabe nicht unterdrückt, sondern verarbeitet. Z.B. erfolgt KEINE Konvertierung von "<" in "<" und somit werden alle Zeilenumbrüche (<br>) auch ausgegeben.
Das SELFHTML spricht hier auch von "benannten Zeichen" oder auch "HTML-Zeichenreferenz".
Persönliche Funktionen:
Wenn eine Zeichenkodierung noch nicht von PHP unterstützt wird, dann ist es möglich selbst eine Funktion zu schreiben, welche die Konvertierung vornimmt. Dafür muss dem Parameter HtmlCharSet der Wert '=myfunction' übergeben werden. Die persönliche Funktion muss einen String als Parameter bekommen und einen konvertierten String zurückgeben.
Die Datei an das Ende des aktuellen (benutzten) Templates anhängen:
Man kann das Schlüsselwort '+' anstatt der Zeichenkodierung, damit die Datei an das Ende des aktuellen (benutzten) Templates angehangen wird. Der Parameter für die Zeichenkodierung bleibt mit dem des ersten Templates identisch. (Anmerkung von CVB: Ich habe nicht herausgefunden, was dieser Parameter bewirkt bzw. ob er etwas verändert.)
Diese Methode erstellt Blöcke mit verschiedenen Daten. Es kann ein oder mehrere TBS Blöcke mit Datensätzen gefüllt werden. Die Datenquelle ist kann z.B. ein Array oder eine SQL-Abfrage. Die Methode gibt die Anzahl der angezeigten Datensätze an. Im Gegensatz zu PHP-Arrays beginnt TBS hier mit 1.
TinyButStrong unterstützt folgende Datentypen:
PHP-Daten: Arrays, Strings und Zahlen.
Datenbanken: MySQL, PostgreSQL und SQLite.
Es ist möglich zusätzliche RDBMS-Typen anzulegen.
Es gibt einen "Seitenmodus" der unten erklärt wird.
Syntax: int $TBS->MergeBlock(string BlockName, mixed Source{, string Query}{, int PageSize, int PageNum}{, int RecCount})| Argument | Beschreibung | ||||||||
| BlockName | Gibt den Namen des TBS Blocks an, der erstellt werden soll. Dieser Name muss im PHP-Skript und im Template identisch sein. Man kann mehrere Blöcke mit den gleichen Daten füllen. Dazu muss man die Namen der Blöcke angeben und mit Komma trennen. | ||||||||
| Source | Gibt die Datenquelle an. Die untenstehende Tabelle gibt die möglichen Arten der Datenquelle an (Array, MySQL, etc.) | ||||||||
| Query | Optional. Hier kann eine SQL-Abfrage übergeben werden. Die Methode "MergeBlock" übernimmt die Auswertung der Abfrage und die Ausgabe in den Block (des Templates). Die untenstehende Tabelle zeigt die verschiedenen Möglichkeiten, wie man mit einem RDBMS (wie MySQL) arbeitet. | ||||||||
| PageSize | Optional. Dieses Argument muss aktiviert werden, wenn man den Seitenmodus benutzen möchte. Der Parameter gibt an, wie viele Datensätze auf einer Seite angezeigt werden soll. | ||||||||
| PageNum | Optional. Dieses Argument muss aktiviert werden, wenn man den Seitenmodus benutzen möchte. Der Parameter gibt an, wie viele Seiten angezeigt werden. Die erste Seite erhält die Zahl 1. Ein Spezialwert -1 zeigt die letzte Seite mit den Datensätzen an. | ||||||||
| RecCount | Optional. Dieses Argument ist nur dann sinnvoll, wenn man den Seitenmodus benutzen möchte. Es erlaubt die Berechnung der Datensätze, die von der Methode "MergeBlock" zurück gegeben werden, anzupassen.
Mann kann den Parameter benutzen, um die gesamte Anzahl der Datensätze zu berechnen und zu speichern. Beispiel: if (isset($_POST['nbr_rec'])) {
$nbr_rec = $_POST['nbr_rec'] ; } else { $nbr_rec = -1 ; } $nbr_rec = $TBS->MergeBlock('blk1',$cnx_id,'select * from t_country',$p_size,$p_num,$nbr_rec); |
Die Methode "MergeBlock" sucht im Template den spezifizierten TBS Block. Beide sind im Regelfall durch einen eindeutigen Namen gekennzeichnet. Danach wird der Block so oft wiederholt, wie es Datensätze gibt.
Um die Daten anzuzeigen, muss man ein TBS Feld (Templatevariable) verwenden, das in Beziehung zur Datenquelle steht. Ein TBS Feld steht in Beziehung zu einem Blocknamen. Die Beziehung/Verlinkung erfolgt durch die Verwendung des Blocknamens, einem Punkt und der Spaltenname (RDBMS) oder einem assoziativen Index eines Arrays. Das verlinkte Feld muss innerhalbs des definierten Blocks stehen.
Beispiel:
Blockname: block1
Spalten die von der SQL-Abfrage zurückgegeben werden: field1, field2, field3
Verlinkte TBS Felder: [block1.field1], [block1.field2], [block1.field3]
Wenn im Template kein Block definiert wurde, dann wird "MergeBlock" nur den ersten Datensatz ausgeben. Man kann auch komplizierte Blockstrukturen verwenden. Siehe TBS Blöcke für mehr Informationen.
| Data Source Type | Source | Query |
| Text (*) | The keyword 'text' | A text |
| Number (*) | The keyword 'num' | A number or a special array (see below) |
| Clear (*) | The keyword 'clear' | - |
| Conditional (*) | The keyword 'cond' | - |
| PHP Array (*) | A Php array | - |
| The keyword 'array' | A Php Array | |
| The keyword 'array' | A string that represents an array contained or nested in a PHP global variable (see below) | |
| MySQL | A MySql connection identifier or the keyword 'mysql' | An SQL statement |
| A MySql result identifier | - | |
| PostgreSQL | A PostgreSql connection identifier | An SQL statement |
| A PostgreSql result identifier | - | |
| SQLite | An SQLite connection identifier | An SQLite statement |
| An SQLite result identifier | - | |
| custom |
A keyword, an object or a resource identifier not mentioned in this table. See the chapter 'adding a data source type'. |
An SQL statement or something else. |
| arg Query | Returned Record Set |
| Number: | This number has to be positive or equal to zero. The returned Record Set consists of a column 'val' where the value goes from 1 to this number . |
| Array: | This array has to contain a key 'min' and a key 'max' and eventually a key 'step'. The returned Record Set consists of a column 'val' which goes from the 'min' value to the 'max' value. Example: array('min'->101,'max'->150) will display 50 blocks numbered from 101 to 150. |
| Example: | ['key1']=>value1 ['key2']=>value2 ... |
| Example: | [0] => (['column1']=>value1-0 ; ['column2']=>value2-0 ; ...) [1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...) [2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...) ... |
| Argument | Description |
| CacheId | Unic id of the cache file. This must be a string, and it will be used in the name of the file. |
| Action/MaxAge | Determine the action to do. It must a be a TinyButStrong's predefined constant or a positive value. See table below for more details on available actions. The default value is 3600 wich correspond to an automatic backup with a max age of 1 hour. |
| Dir | Optional. The path of the directory where the cache file is saved. By default, it is the same directory as the script. |
| Action | Description | ||||
| x >=0 (positive number) |
Automatic Mode with max-age:
|
||||
| TBS_CACHENOW | Save the current result of the merge in the cache file corresponding to CacheId. CacheAction() returns false. |
||||
| TBS_CACHELOAD | Load the cache file corresponding to CacheId. CacheAction() returns true if the cache file has been found and loaded, otherwise it returns false. |
||||
| TBS_DELETE | Delete the cache file corresponding to CacheId, if it exists. You can delete all the cache files of the directory using '*' for CacheId. CacheAction() returns false. |
||||
| TBS_CACHEONSHOW | Start "Cache on show" for the cache file corresponding to CacheId CacheAction() returns false. |
||||
| TBS_CANCEL | Cancel "Cache on Show" whatever is CacheId. CacheAction() returns false. |
||||
| TBS_CACHEGETAGE | Return the age of the cache file in seconds. Return false if the cache file doesn't exist. | ||||
| TBS_CACHEGETNAME | Return the name of the cache file corresponding to the given CacheId. A name is returned even if the cache file doesn't exist yet. |
||||
| TBS_CACHEISONSHOW | Return true if "Cache on show" is activated, otherwise, return false. |
| Argument | Description |
| BlockName | The name of the block to search for. |
| Sections | Optional. The default value is False. If this parameter is set True the Methode returns an array that contains the definitions for all the sections of the named block. The first section is returned into the item [1] of the array. |
| 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. |
| FunctionMode | Indicates that the value to display is calculated by a user function. The default value is false. If this argument is set to true, then X must be a text string giving the name of the user function. This function must exist and have the syntax described below. |
Syntax: $TBS->MergeNavigationBar(string NavName, mix Options, int PageNum [, int RecCount, int PageSize])
| Argument | Description | ||||||||||
| NavName | The name of the navigation bar. |
||||||||||
| Options | Enables you to force some options of the navigation bar. Those options can also be defined using block parameters in the template. But if you put them at the MergeNavigationBar() too, they will be forced. This parameter can be blank ('', 0 or null), a numeric value or an array. If it's a numeric value, it indicates the number of pages displayed. If it's an array, it can contain the following items:
|
||||||||||
| PageNum | Number of the active page. The first page is number 1. To indicate the last page, use the value -1. |
||||||||||
| RecCount | Optional. The default value is -1. Indicates the total number of records, if known. If this number is unknown, you have to put the value -1. This argument is used only to calculate the number of the last page of the navigation bar. |
||||||||||
| PageSize | Optional. The default value is 1. Indicates the number of records per page. It has to be used together with RecCount. It is used only to calculate the number of the last page of the navigation bar. |
| Value | Description |
| 'var' | Replaces all Var fields. |
| 'onload' | Replaces all onload fields. |
| 'onshow' | Replaces all onshow fields. |
| Constant | Description |
| TBS_NOTHING | Indicates that none of the actions below are proceeded 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. |
| Argument | Description |
| $Source | Is the same argument given to the MergeBlock() Methode. |
| $Query | Is the same argument given to the MergeBlock() Methode. |
| Argument | Description |
| $Rs | The Record Set identifier returned by the tbsdb_customdb_open() function. |
| $RecNum | Optional. The number of the expected record. First is number 1. |
| Argument | Description |
| $Rs | The Record Set identifier returned by the tbsdb_customdb_open() function. |
| Features | Example |
| Var Fields | [var.~prop1] ... [var.~.key1.prop1] ... [var.~meth1] ... [var.~prop2.subprop] |
| Parameter ondata | [blk1.column1;block=tr;ondata=~meth_ondt] |
| Parameter onformat | [blk1.column2;onformat=~meth_onfrm] |
| MergeField() Methode | $TBS->MergeField('fldname','~meth_MrgFld',true); |
| Custom Data Functions (*) | $TBS->MergeBlock('blk1','~mydb','SELECT * FROM t_table'); |
| Custom Html conversion function | $TBS->LoadTemplate('mytemplate.htm','=~meth_htmlconv'); |
| Element | Description |
| FieldName | The name of the Field. Warning: names that begin with var. , onload and onshow are reserved. They are respectively used for Var fields, and Automatic fields. |
| params | Optional. One or more parameters from the list below and separated with ';'. Some parameters can be set to a value using the equal sign '='. Example: frm=0.00 If the value contains spaces or semicolons, you can use single quotes. Example: frm='0 000.00'. It is possible to embed TBS fields. It means you can write this: [var.v1; if [var.v2]=1]. But: - for Var fields, you have to make sure that v2 will be merged before v1. - for block fields, you have to make sure that column v2 is before column v1. |
| Parameter | Description | ||||||||||||||||||||||||||||||||||||||||||||||
| 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:
|
||||||||||||||||||||||||||||||||||||||||||||||
| . (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. | ||||||||||||||||||||||||||||||||||||||||||||||
| magnet=tag | Assign a magnet Html tag to the TBS field. A magnet tag is kept as is when the field has a value, and is deleted when the field is null or empty string. Example:
By default, the magnet Html tag should be a pair of opening-closing tags (like <a></a>) which first tag is placed before the TBS fields. But this can be changed using parameter mtype (see below). (<a href="[var.link;magnet=a]">click here</a>) Result for $link='www.tbs.com': (<a href="www.tbs.com">click here</a>) Result for $link='': () Remark: the parameters if then else are processed before parameter magnet. |
||||||||||||||||||||||||||||||||||||||||||||||
| mtype=val | To be used with parameter magnet. Define the magnet type.
|
||||||||||||||||||||||||||||||||||||||||||||||
| selected | This parameter enables you to select an item for a List, Radio buttons or Checkboxes placed into a Html form. You have to ensure that items are created (merged) before the merge. Html List:
Use the parameter selected without setting a value to it. The TBS Field has to be placed within the list of values. When the TBS field is merged it is deleted, but the item which has the same value as the field will be selected. If the value is not found, a new item is added.
Radio buttons and Checkboxes:
Use the parameter selected with setting a value to it which is the name of the Radio buttons or Checkboxes to process. The TBS Field has to be placed within the form. When the TBS field is merged it is deleted, but the item which has the same value as the field will be selected.
Multi-selection:
For Lists, Radio buttons or Checkboxes, you can make a multi-selection by giving a Php array as the value of the TBS field.Bounds: By default the bounds for searching items to select are html tags <select> for List , and <form> for Radio buttons and Checkboxes. But you can change them using parameter selbounds (see below). |
||||||||||||||||||||||||||||||||||||||||||||||
| selbounds=tag | To be used with parameter selected. It enables you to change the search zone for items to select by indicating a Html tag type. By default, this value is select for a List, and form for Radio buttons and Checkboxes. Example: [town_id;selected=r_test;selbounds=div] In this example, items to select will be searched between <div> and </div> tags that surround the TBS field. |
||||||||||||||||||||||||||||||||||||||||||||||
| comm | This parameter enables you to widen the bounds of the TBS Field up to the bounds of the commentary Html tag which surround it. <!-- [myfield;comm] this is an example--> is strictly identical to [myfield] This is particularly useful for the template designing when you are using a Visual HTML Editor (such as Dreamweaver or FrontPage). |
||||||||||||||||||||||||||||||||||||||||||||||
| noerr | Avoid some of the TBS Error messages. When a message can be cancelled, it is mentioned in the message. | ||||||||||||||||||||||||||||||||||||||||||||||
| file=filename | Replace the field with the contents of the file. Filename can be a string or an expression built with Var fields that returns the file path. How to use this parameter is detailed in the chapter Subtemplates. |
||||||||||||||||||||||||||||||||||||||||||||||
| script=filename | Execute the Php script just before replacing the locator. Filename can be a string or an expression built with Var fields that returns the file path.
|
||||||||||||||||||||||||||||||||||||||||||||||
| 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. |
||||||||||||||||||||||||||||||||||||||||||||||
| once | To be used with the parameter script. Cancel the script execution if it has previously been called. |
||||||||||||||||||||||||||||||||||||||||||||||
| getob | This parameter is deprecated because it can be replaced with parameter subtpl. To be used with the parameter script. Indicates that the text displayed using the echo() command in the Php script replaces the value of the TBS Field. |
||||||||||||||||||||||||||||||||||||||||||||||
| if expr1=expr2 | Display the data item only if the condition is verified, otherwise display nothing unless parameter then or else are used. Supported operators are:
See parameters then and else for some examples. |
||||||||||||||||||||||||||||||||||||||||||||||
| then val1 | If the parameter if is defined and its condition is verified, then the data item is replaced with val1. Example: [var.image;if [val]='';then 'image0.gif'] |
||||||||||||||||||||||||||||||||||||||||||||||
| else val2 | If the parameter if is defined and its condition is not verified, then the data item is replaced with val2. Example: [var.error_id;if [val]=0;then 'no error';else 'error found'] |
||||||||||||||||||||||||||||||||||||||||||||||
| onformat=fct_name | Indicates the name of a user Php function that will be executed before the merge of the field. The function fct_name must have the following syntax: function fct_name($FieldName,&$CurrVal,{&$CurrPrm,{&$TBS}}) { ... }
|
||||||||||||||||||||||||||||||||||||||||||||||
| protect=val | Enables you to protect or unprotect the data item to be merged by replacing the characters '[' with their corresponding Html code '['. The value val can be one of the following keywords: yes: (default value) data item is protected. no: data item is not protected. By default, all data merged with a template is protected except if it's a file inclusion. It is strongly recommended to protect data when it comes from free enter like on a forum for example. |
||||||||||||||||||||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||||||||||||||||||||
| frm=format | Specify a format to display a data item of type date/time or numeric. For a numeric item, it is possible to use a conditional format which changes depending on the sign of the value. Date-time format:
It is a VisualBasic like format. The following keywords are recognized:
Other characters are kept. It is possible to protect the strings inside by putting them between single or double quotes. Examples: [fld;frm=mm/dd/yyyy] will display 12/21/2002 [fld;frm='yyyy-mm-dd hh:nn:ss'] will display 2002-12-21 15:45:03 Numeric format:
To define the decimal part, use an expression like '0x0...' where 'x' 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 '0z000x...' where 'z' is the thousand separator. If there is no decimal, use the format '0z000.' (with a dot). If the format contains the character '%', then the value to display will be multiplied by 100. The character '%' is displayed too. The numerical format may contain other strings. But only the expression with one or more zeroes placed to the right will be taken as a format, other characters will be kept. Examples:
Conditional formats:
You have the possibility to define up to 4 conditional formats when the value is respectively positive, negative, zero or null (or empty string). Conditional formats must be separated by a '|' character. Each conditional format is optional. Examples:
|
||||||||||||||||||||||||||||||||||||||||||||||
| locale | To be used with the parameter frm. Indicates that the format specified with frm must display locale day and month's names. Locale informations can be set using the PHP function setlocale(). |
||||||||||||||||||||||||||||||||||||||||||||||
| tplvars | Enables you to define variables in the template that you can retrieve in the Php programm using TplVars property. Works only with onload automatic fields. |
| Name | Description |
| var..now | Date and hour of the server. |
| var..version | The version of TinyButStrong. |
| var..script_name | The name of the PHP file currently executing. |
| var..template_name | The name of the last loaded template file. It is the name given to the LoadTemplate() Methode. |
| var..template_date | The creation date of the last loaded template file. |
| var..template_path | The directory of the last loaded template file. It is the directory given to the LoadTemplate() Methode. |
| var..tplvars.* | The value of an item set in the TplVars property. ('*' must be the key of an existing item in the array) |
| Parameter | Description | ||||||||||||
| extend=n extend=tag1,tag2,... |
Extend the block definition upon more tags. This parameter has effect only with the relative syntax or the simplified syntax of blocks. It enables you, for example, to define a block on two rows of a table. Syntax 1: using a number n (positive or negative) Extend the block definition upon the n next pairs of tags that follow. Tag's names are the same as parameter block. If n is negative, then the block is extended upon the previous pairs of tags. Syntax 2: using a list of tag names Extend the block definition upon the pairs of tags that follow. Tags are those given by the list . |
||||||||||||
| encaps=num | Indicates encapsulation level of the TBS tags compared to the HTML tags specified with the parameter block. The default value is 1. Example:
In the example above, the blue row will be duplicated during the merging because there is 'encaps=2'. If 'encaps=1' is set or if the parameter is left off, then it will be the pink row that is duplicated in the merging. |
||||||||||||
| comm | This parameter enables you to widen the bounds of the TBS tag up to the bounds of the commentary tag (HTML) surrounding it. <!-- [block1;block=tr;comm] this is an example--> is strictly identical to [block1;block=tr] This parameter is particularly useful for designing the template when using a visual HTML editor (such as Dreamweaver or FrontPage). |
||||||||||||
| nodata | Indicates a section that is displayed only if there is no data to merge. Example:
For more information about sections, see the chapter 'Sections of blocks'. |
||||||||||||
| 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. You can define several headergrp sections with different columns. Placement's order of headergrp sections in the block can modify the result. For more information about sections, see the chapter 'Sections of blocks'. |
||||||||||||
| footergrp=colname | Indicates a footer section that is displayed each time the value of column colname changes. See headergrp. | ||||||||||||
| splittergrp=colname | Indicates a splitter section that is displayed each time the value of column colname changes. See headergrp. | ||||||||||||
| parentgrp=colname | Indicates a parent section that is displayed each time the value of column colname changes. Unlike other sections, a parentgrp section allows normal sections inside itself. It's a way to define both a header and a footer in one section. | ||||||||||||
| serial | Indicates that the block is a main block which contains serial secondary blocks. For more information, see the chapter 'serial display (in columns)'. |
||||||||||||
| p1=val1 | Indicates the use of a dynamic query. All the occurrences of the string '%p1%' found in the query given to the MergeBlock() Methode are replaced by the value val1. For more information, see the chapter 'dynamic queries / sub-blocks'. |
||||||||||||
| ondata=fct_name | Indicates the name of a user Php function that will be executed during the block merging. The function is called each time a record is taken from the data source. You can use the arguments of such a Php function to edit records before they are merged. The function must have the following syntax: function fct_name($BlockName,&$CurrRec,$RecNum) { ... }
function f_add_column($BlockName,&$CurrRec,$RecNum) { $CurrRec['len'] = strlen($CurrRec['text']); } |
||||||||||||
| onsection=fct_name | Use this parameter with care because it may not be supported in the future. It is kept for compatibility purpose, and you should use parameter ondata instead which is faster. Parameter onsection works the same way as ondata, except that the Php function is called each time a section is merged. So if your block contains header sections or conditional sections, then the function may be called several times for the same record. Syntax of the Php function: function fct_name($BlockName,&$CurrRec,&$DetailSrc,$RecNum) { ... } Argument $DetailSrc returns the source of the current section (read/write ; don't forget the & in the function header). If you set this variable to '', it cancels the displaying of this record. |
||||||||||||
| when expr1=expr2 | Make the section conditional and define its condition. A conditional section is displayed only if its condition is verified. Supported operators are:
|
||||||||||||
| default | Indicates a section of block that must be displayed only if no conditional section of the same block has been displayed. | ||||||||||||
| several | Indicates that several conditional sections of the block can be displayed if several conditions are true. By default, conditional sections are exclusive. | ||||||||||||
| [b1.caption;block=tr] |
| [b1.caption;block=tr] |
| [b1.caption;block=tr] |
| There is nothing. [b1;block=tr;nodata] |
| Year: [b1.year;block=tr;headergrp=year] | |
| [b1.caption;block=tr] | [b1.amount] |
| [b1.name;block=tr] |
| [b1.address;block=tr;when [b1.add_ok]==1] |
|
||||
|
||||
|
|
|
||||
|
| [blk.town;block=tr;p1='france'] | [blk.country] |
| [blk.town;block=tr;p1='us'] | [blk.country] |
| Paris | france |
| Toulouse | france |
| Washington | us |
| Boston | us |
Country: [main.country;block=table]
|
Country: France
|
||
Country: Germany
|
||
Country: Spain
|
| Name | Description |
| page | Returns the number of a common page, reachable from the navigation bar. |
| curr | Returns the number of the active page. |
| first | Returns the number of the first page (1 by default). |
| prev | Returns the number of the previous page. |
| next | Returns the number of the next page. |
| last | Returns the number of the last page if it's known, otherwise returns -1. |
| |< | < | [nav.page;block=td] | [nav.page;block=td;currpage] | > | >| |
| |< | < | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | > | >| |
| Parameter | Description |
| navsize=num | Number of pages displayed in the navigation bar. (default = 10). |
| navpos=keyword | Position of the navigation bar compared to the active page number. Use one of the following keywords: - 'step' (by default) to have the bar progressing by step. - 'centred' to center the bar on the active page number. |
| navdel=blockname | Name of a TBS block to delete when there is only one page or no page to display. This TBS block must surroud the navigation bar. If there are several pages to display then only TBS definition tags of this bloc are deleted. |
| pagemin=num | Number of the first page (default = 1). |
| [onload;block=tr;when [var.status]==1] Status 1 |
| [onload;block=tr;when [var.status]==2] Status 2 |
| * | Php outputs are displayed at the field's place instead of being immediately sent to the client. For example, using the Php command echo() will insert a text in the main template instead of be directly output it. Using the Show() Methode will also insert the result of the sub-merge into the main template. |
| * | A reference to the TBS instance is provided by local variable $this or $TBS, whether you use parameter script or onformat. This variable be used for new submerges without deteriorating the main template. The Show() Methode won't stop any script execution during the Subtemplate mode like it does by default in normal mode. |
| HTML: | [var.file;script=specialbox.php;subtpl] |
| PHP script: | <?php echo('* Here include a subtemplate *'); $this->LoadTemplate($CurrVal); $this->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1'); $this->Show(); ?> |
| Remarks: | $CurrVal is a local variable provided by TBS when using parameter script ; this variable is a reference to the value of the field currently merged. In the example above, $CurrVal has the value of the global variable $file. You can replace it, for example, by the name of the subtemplate to load (for example: 'mysubtpl.htm'). See parameter script for more information. |
| HTML: | [var.user_mode;onformat=f_user_info;subtpl] |
| PHP user function: | function f_user_info($FieldName,&$CurrVal,&$CurrPrm,&$TBS) { if ($CurrVal==1) { // User is logged in $TBS->LoadTemplate('user_info.htm'); $TBS->MergeBlock('blk1',$GLOBALS['conn_id'],'SELECT * FROM table1'); $TBS->Show(); } else { // User not logged in echo('You are not logged in.'); } } |
| Remarks: | $CurrVal is a variable declared as an argument of the function. It's TBS that is in charge to call this function making $CurrVal referring to the value of the fields currently merged. In this example above, $CurrVal is equal to the global variable $user_mode. In the same way, variable $CurrPrm is a reference to the array of parameters of the field currently merged, and $TBS is a reference to the TinyButStrong instance currently used. See parameter onformat for more information. |
| Parameter | Description |
| . (dot) | Display an Html unbreakable space if the field value is empty. |
| ifempty=value2 | Display value2 if the field value is empty. |
| magnet=tag | Delete a tag or a pair of tags if the field value is empty. |
| if condition then value1 else value2 |
Display value1 or value2 depending on whether the condition is verified or not. |
| frm=format1|format2|format3|format4 | Changes the numeric format or date/time format depending on whether the value is positive, negative, zero or empty. |
| Name: [b1.Name;block=tr] | normal 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] | conditional section |
| [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 ? |
| [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. |
| Parameter | Summary |
| htmlconv | Html 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. |
| 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. |
| max | Limits the number of characters. |
| frm | Apply a date-time or a numeric format. |
| locale | Use with frm. Display locale day and month's names. |
| protect | Protection mode for characters '['. |
| selected | Selects items in an Html list. |
| selbounds | Use with selected. Change the default bounds for searching items. |
| 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. |
| subtpl | Use with script or onformat. Turns the TBS instance into subtemplate mode. |
| once | Use with script. Prevent the script from several executions. |
| getob | Deprecated. Use with script. Retrieves texts passed to echo and puts them to the field's place |
| Parameter | Summary |
| block | Defines the block's bounds. |
| extend | Extends the block's bounds upon several successive Html tags. |
| encaps | Extends the block's bounds upon several encapsulated Html tags. |
| comm | Extends the block's bounds up to the Commentary tag that surround it. |
| 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. |
| ondata | Executes a Php user function to modify the record when it has just been taken from the data source. |
| onsection | Executes a Php user function to modify the section currently merged. |
| tplvars | Use with onload fields only. Define template variables. |
| 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. |
| Fields | Summary |
| nav.page | Displays the number of a page. |
| nav.curr | Displays the number of the current page. |
| nav.first | Displays the number of the first page (allways 1). |
| nav.prev | Displays the number of the previous page. |
| nav.next | Displays the number of the next page. |
| nav.last | Displays the number of the last page (-1 if unknown). |
| Parameter | Summary |
| currpage | Indicates a section that is displayed only for the current page. |
| endpoint | Returns an empty string if the current page is the first page or the last page. |
| navpos | Indicates how the navigation bar is positioned compared to the current page number. |
| navsize | Indicates the number of page to display. |
| pagemin | Indicates the number of the first page. |
| Name | Summary |
| val | The keyword [val] can be used in field's parameters to represent the field's value. |
| var.* | Displays a Php variable. |
| var..* | Displays information about the TinyButStrong System. |
| # | Virtual column name for a block. It displays the record's number. |
| $ | Virtual column name for a block. It displays the record's key if the data source is a Php Array. |
| onload | Automatisches Feld oder Block, das mit einem Wert belegt wird, wenn das Template geladen wird. |
| onshow | Automatisches Feld oder Block, das mit einem Wert belegt wird, wenn das Template angezeigt wird. |