forked from javigomez/lib_tbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbs_us_manual.htm
executable file
·3791 lines (3779 loc) · 287 KB
/
tbs_us_manual.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<title>TBS Manual</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
.pagebreak {
page-break-before:always;
}
.tbsname {
font-size: 12px;
font-weight: bolder;
color: #4D3A81;
}
.norm {
margin-left: 30px;
padding: 5px;
border: 1px solid #999999;
margin-top: 12px;
margin-bottom: 12px;
}
.decal {
margin-left: 20px;
padding: 2px;
margin-top: 3px;
}
h1 {
margin-top: 8px;
margin-bottom: 8px;
font-size: 16px;
}
h2 {
font-weight:normal;
font-size: 16px;
text-decoration: underline;
background-color: #6699CC;
margin-top: 20px;
margin-bottom: 20px;
}
h3 {
margin-top: 20px;
margin-bottom: 20px;
font-weight:normal;
font-size: 16px;
text-decoration: underline;
}
h4 {
text-decoration: underline;
font-weight:normal;
font-size: 12px;
margin-top: 8;
margin-bottom: 6;
}
h5 {
font-weight: bold;
font-size: 12px;
margin-top: 3;
margin-bottom: 3;
}
h6 {
text-decoration: underline;
font-weight:normal;
font-size: 12px;
margin-top: 8;
margin-bottom: 6;
}
th {
text-decoration: underline;
text-align:left;
vertical-align:top;
font-weight:normal;
}
pre {
font-size:12px;
}
.title-1c {
font-weight: bold;
}
.txt-small {
font-size: 10px;
}
.txt-code {
font-family: "Courier New", Courier, mono;
font-size: 12px;
}
.txt-tiny {
font-size: 9px;
margin-top:0;
margin-bottom:0;
}
table {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
td {
margin-top:0;
}
p {
margin-top:4;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.opt-name {
color: #990000;
}
a.opt-name {
color: #990000;
text-decoration:none;
}
a.opt-name:hover {
color: #990000;
text-decoration:underline;
}
.opt-value {
color: #000099;
}
.opt-html {
color: #006600;
}
.opt-type {
font-style: italic;
color: #0033CC;
}
.border-0 {
border: 1px solid #999999;
}
.border-1 {
border: 1px solid #FF3399;
}
.border-2 {
border: 1px solid #336699;
}
.border-3 {
border: 1.5px solid #CC6600;
}
.border-sep {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999999;
}
.versioning {
background-color: #EAEAEA;
margin: 12px 0 12px 0;
padding: 0 0 2px 0;
}
.versioning > p {
/* <p> inside a class "versioning" */
margin: 0;
}
.list-mini {
margin: 0;
padding-left: 20px;
}
.blockzone {
border: 1px dotted #666666;
padding: 2px;
margin: 2px;
}
.blocksep {
border-left-width: 1px;
border-left-style: dotted;
border-left-color: #666666;
}
.contextual {
padding: 1px;
border: 1px dotted #6699CC;
}
.note {
background-color: #D9FFD9;
border: thin solid #00EC9F;
padding: 2px;
margin-top: 3px;
margin-left: 20px;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<div id="main-body">
<div class="txt-tiny" style="display:inline-block; float:left;">
<table class="txt-tiny" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50">Site:</td>
<td><a href="http://www.tinybutstrong.com" target="_top">www.tinybutstrong.com</a></td>
</tr>
<tr>
<td>Authors:</td>
<td><a href="http://www.tinybutstrong.com/onlyyou.html">skrol29</a>, Pirjo</td>
</tr>
<tr>
<td>Date:</td>
<td>2012-10-29</td>
</tr>
</table>
</div>
<div style="margin:auto; width:500px; text-align:center;">
<h1>TinyButStrong Documentation</h1>
<div class="txt-tiny">version 3.8</div>
<div style="margin-top:10px;">Template Engine for Pro and Beginners<br>
for PHP 5</div>
</div>
<h2>Table of Contents:</h2>
<div class="norm">
<table border="0" cellspacing="0">
<tr class="title-1c">
<td width="300"> Subject</td>
<td>Description</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a href="#introduction" class="title-1c">• Introduction</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#principles">Basic principles</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#installation">Installation</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#examples">Mini examples</a></td>
<td> </td>
</tr>
<tr>
<td><a href="#php_side" class="title-1c">• PHP side</a></td>
<td> </td>
</tr>
<tr>
<td> • To begin</td>
<td> </td>
</tr>
<tr>
<td> <a href="#php_instanciate">create a new TBS object</a></td>
<td> for working with templates</td>
</tr>
<tr>
<td> <a href="#php_loadtemplate"><span class="txt-small">method</span> LoadTemplate()</a></td>
<td>load the contents of a template from a file</td>
</tr>
<tr>
<td> <a href="#php_mergeblock"><span class="txt-small">method</span> MergeBlock()</a></td>
<td>merge a part of the template with a data source</td>
</tr>
<tr>
<td> <a href="#php_show"><span class="txt-small">method</span> Show()</a></td>
<td>automatic processing and display of the result</td>
</tr>
<tr>
<td> • Advanced</td>
<td> </td>
</tr>
<tr>
<td> <a href="#php_getblocksource"><span class="txt-small">method</span> GetBlockSource()</a></td>
<td>returns the source of the definition of a block</td>
</tr>
<tr>
<td> <a href="#php_mergefield"><span class="txt-small">method</span> MergeField()</a></td>
<td>merge a specific field with a value</td>
</tr>
<tr>
<td> <a href="#php_setoption"><span class="txt-small">method</span> SetOption()</a></td>
<td>set TBS options</td>
</tr>
<tr>
<td> <a href="#php_getoption"><span class="txt-small">method</span> GetOption()</a></td>
<td>get TBS options</td>
</tr>
<tr>
<td> <a href="#php_plugin"><span class="txt-small">method</span> PlugIn()</a></td>
<td>execute a plug-in's action </td>
</tr>
<tr>
<td> <a href="#php_varref"><span class="txt-small">property</span> VarRef</a></td>
<td>set variables to be merged with automatic fields</td>
</tr>
<tr>
<td> <a href="#php_assigned"><span class="txt-small">property</span> Assigned</a></td>
<td>prepares information for a subsequent merging</td>
</tr>
<tr>
<td> <a href="#php_source"><span class="txt-small">property</span> Source</a></td>
<td>returns the current contents of the result</td>
</tr>
<tr>
<td> <a href="#php_tplvars"><span class="txt-small">property</span> TplVars </a></td>
<td>returns template variables </td>
</tr>
<tr id="v202_oop_plan">
<td> <a href="#php_oop">Object Oriented Programming (OOP) </a></td>
<td>to make TBS OOP friendly </td>
</tr>
<tr>
<td><a href="#html_side" class="title-1c">• Template side</a></td>
<td> </td>
</tr>
<tr>
<td> • TBS fields</td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_field">Definition and syntax</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_field_prm">Parameters</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_field_prm_order">Order of processing parameters</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_field_auto">Automatic fields</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_field_special">Special automatic fields</a></td>
<td> </td>
</tr>
<tr>
<td> • TBS blocks</td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block">Definition and syntaxes </a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_prm">Parameters</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_section">Sections of block</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_auto">Automatic blocks </a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_serial">Serial display (in columns) </a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_subblock">Subblocks</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_subauto">Automatic subblocks</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_block_dynsb">Subblocks with dynamic queries</a></td>
<td> </td>
</tr>
<tr>
<td> • Miscellaneous</td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_subtemplate">Subtemplates</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#html_conditional"> Conditional display overview</a></td>
<td> </td>
</tr>
<tr>
<td><a href="#coding" class="title-1c">• Improve TBS by coding</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#coding_extended_methods">Extended methods</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#coding_block_alias">Block alias</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#plugins_db">Database Plug-ins</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#plugins_tbs">Other plug-ins</a></td>
<td> </td>
</tr>
<tr>
<td><a href="#summaries" class="title-1c">• Summary</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#appendix_field">TBS Field's parameters</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#appendix_block">TBS Block's parameters</a></td>
<td> </td>
</tr>
<tr>
<td> <a href="#appendix_specialname">Names of Special Fields and Blocks</a></td>
<td> </td>
</tr>
</table>
</div>
<h2 id="introduction" class="pagebreak">Introduction:</h2>
<p><strong>TinyButStrong</strong> (TBS) is a PHP class useful to develop an application in a clean way, separating PHP scripts and XML/HTML/Text files. With TBS, the files are generated dynamically by merging a template with data. It is called a Template Engine. </p>
<p> The name TBS comes from the fact that this tool contains only 8 functions and yet, it is very powerful. It allows you to merge templates with your PHP variables or your MySQL, PostgreSQL, or SQLite.</p>
<p> TBS has been engineered so that you can develop your templates with ease using any visual editors (like Dreamweaver or FrontPage). But if you are used to designing your templates with a text editor, it is nice as well. TBS also enables you to create JavaScript dynamically.</p>
<p> As the name of it tells, TBS is easy to use, strong and fast. It is completely <span style="color:#009900">°~° freeware °~°</span>. </p>
<h3><a name="principles" id="principles"></a>Basic principles:</h3>
<p>On the HTML side (or other file type):<br>
You design a page which does not necessarily contain any PHP scripts, nor any programming. In this page you place TBS tags in the places where you want to display the dynamic data. This page is called a 'template'.<br>
There are two types of tags: the <a href="#html_field">'fields'</a> which are used to display dynamic data items, and the <a href="#html_block">'blocks'</a> which are used to define an area, mostly in order to display records from a data source.</p>
<p> On the PHP side:<br>
You use an object TBS variable to manage the merge of your template with the data. At the end, TBS shows the result of the merge. </p>
<h3><a name="installation"></a>Installation:</h3>
<ol>
<li>Copy the file <span class="opt-html">tbs_class.php</span> in a directory of your Web site.</li>
<li>At the beginning of your PHP program, add the lines:
<pre class="decal txt-code">
include_once(<span class="opt-value">'tbs_class.php'</span>);
<span class="opt-name">$TBS</span> = new clsTinyButStrong; </pre>
<p><span class="txt-small">Remark: if the TBS file tbs_class.php is in a different directory than your application, then you have to precise the directory in front of the TBS file name.</span></p>
</li>
</ol>
<h4>Explanations and technical details:</h4>
<p>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.</p>
<p> The variable $TBS that you add at the beginning of your PHP program enables you to execute the merge of your template from your PHP application. In technical terms, the variable $TBS is an 'instance' of the clsTinyButStrong class. </p>
<h3><a name="examples" id="examples"></a>Mini examples:</h3>
<p>Example 1: </p>
<table border="0" cellpadding="2" cellspacing="4">
<tr>
<th width="320">Html Template</th>
<th width="320">Php Program</th>
<th>Result</th>
</tr>
<tr>
<td valign="top"><pre class="opt-html">
<html>
<body>
[onshow.message]
</body>
</html>
</pre></td>
<td valign="top"><pre class="txt-code">
<?php
include_once(<span class="opt-value">'tbs_class.php'</span>);
<span class="opt-name">$TBS</span> = new clsTinyButStrong;
<span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-value">'template.htm'</span>);
$message = <span class="opt-value">'Hello'</span>;
<span class="opt-name">$TBS</span>->Show();
</pre></td>
<td valign="top" ><pre class="opt-html"><html>
<body>
Hello
</body>
</html></pre></td>
</tr>
</table>
<p>Example 2: </p>
<table border="0" cellpadding="2" cellspacing="4">
<tr>
<th width="320">Html Template</th>
<th width="320">Php Program</th>
<th>Result</th>
</tr>
<tr>
<td valign="top"><pre class="opt-html"><table>
<tr><td>[blk.val;block=tr]</td></tr>
</table></pre></td>
<td valign="top"><pre class="txt-code"><?
include_once(<span class="opt-value">'tbs_class.php'</span>);
<span class="opt-name">$TBS</span> = new clsTinyButStrong;
<span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-value">'template.htm'</span>);
$list = array(<span class="opt-value">'X'</span>,<span class="opt-value">'Y'</span>,<span class="opt-value">'Z'</span>);
<span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'blk'</span>, $list);
<span class="opt-name">$TBS</span>->Show();
</pre></td>
<td valign="top"><pre class="opt-html"><table>
<tr><td>X</td></tr>
<tr><td>Y</td></tr>
<tr><td>Z</td></tr>
</table></pre></td>
</tr>
</table>
<a name="php_side"></a>
<h2>PHP side:</h2>
<p>The merging of a template is done in a PHP program using an object variable declared as a <span class="opt-html">clsTinyButStrong</span> class.<br>
Example of statement: <span class="txt-code"><span class="opt-name">$TBS</span> = new clsTinyButStrong;</span> <br>
This object allows you to load a template, to handle the merging of it with data, and then to show the result.</p>
<p> Example of PHP code: </p>
<pre class="txt-code decal">include_once(<span class="opt-value">'tbs_class.php'</span>);
<span class="opt-name">$TBS</span> = new clsTinyButStrong;
<span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-value">'template.htm'</span>) ;
<span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'ctry','mysql','SELECT * FROM t_country'</span>);
<span class="opt-name">$TBS</span>->Show();</pre>
<p>Here is the description of the TinyButStrong object: </p>
<h3><a name="php_instanciate" id="php_instanciate"></a>create a new TBS object:</h3>
<div class="norm">
<p>A TBS object is created as a new instance of the clsTinyButStrong class. A TBS object enables you to work with one or several templates using the object's methods and properties.</p>
<p> Syntax to create a new TBS object as of version 3.8.0: <span class="txt-code"><span class="opt-name">$TBS</span> = new clsTinyButStrong({<span class="opt-type">array</span> <span class="opt-name">Options</span>})</span></p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th width="80">Argument</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">Options</td>
<td align="left" valign="top">An array of options to set for the option of the template engine. See all available options at the <a href="#php_setoption">SetOption</a> section.</td>
</tr>
</table>
<p>Examples:</p>
<pre class="decal txt-code"><span class="opt-name">$TBS1</span> = new clsTinyButStrong; <span class="opt-html"> // default behavior</span>
<span class="opt-name">$TBS2</span> = new clsTinyButStrong(<span class="opt-value"> array('chr_open'=></span><span class="opt-value">'{', 'chr_close'=>'}')</span> ); <span class="opt-html">// TBS tags will be like {var.x} instead of [var.x]</span>
<span class="opt-name">$TBS3</span> = new clsTinyButStrong(<span class="opt-value"> array('var_prefix'=></span><span class="opt-value">'tbs_fct_')</span> );<span class="opt-html"> // TBS will display only PHP global variables beginning with 'tbs_var_</span>'
<span class="opt-name">$TBS4</span> = new clsTinyButStrong(<span class="opt-value"> array('fct_prefix'=></span><span class="opt-value">'tbs_fct_') </span>);<span class="opt-html"> // TBS will call only PHP function beginning with 'tbs_fct_'</span></pre>
<div class="versioning">
<p>Versioning:</p>
<p>Before TBS version 3.8.0, the syntax to create a new TBS object was:<br>
<span class="txt-code"><span class="opt-name">$TBS</span> = new clsTinyButStrong({string <span class="opt-name">chr_delim</span> {, string <span class="opt-name">var_prefix</span> {, string <span class="opt-name">fct_prefix</span>}}});</span><br>
where: </p>
<ul class="list-mini">
<li><span class="opt-name"> chr_delim</span> is the concatenation of (the option <a href="#php_setoption_chr_open" class="opt-name">chr_open</a> + the string ',' + the option <a href="#php_setoption_chr_close" class="opt-name">chr_close</a>). For example: '{,}'</li>
<li><span class="opt-name">var_prefix</span> is the value for the option <a href="#php_setoption_var_prefix" class="opt-name">var_prefix</a></li>
<li><span class="opt-name">fct_prefix</span> is the value for the option <a href="#php_setoption_fct_prefix" class="opt-name">fct_prefix</a></li>
</ul>
</div>
<h3><a name="php_loadtemplate" id="php_loadtemplate"></a>method LoadTemplate():</h3>
<div class="norm">
<p>Loads a template for the merging process. The complete contents of the file is immediately stored in the <a href="#php_source">Source</a> property of the TBS object, then [onload] <a href="#html_field_auto">fields</a> and <a href="#html_block_auto">blocks</a> are merged. If the file is not found, then it will also be searched in the folder of the last loaded template (<span class="versioning">since TBS version 3.2.0</span>).</p>
<p> Syntax: <span class="txt-code"><span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-type">string</span> <span class="opt-name">File</span><span class="opt-name"><span style="color:#333333">{</span></span>, <span class="opt-type">string</span><span class="opt-name"> Charset<span style="color:#333333">}</span></span>)</span> </p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">File</td>
<td align="left" valign="top">Local or absolute path of the file to load.<br>
This value can be <span class="opt-value">null</span> or <span class="opt-value">''</span> (empty string) for special actions. See below for more details. </td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">Charset</td>
<td align="left" valign="top"><p>Optional. Will set the <a href="#php_setoption_charset" class="opt-name">charset</a> option.</p></td>
</tr>
</table>
<h4>Scope of the file path:</h4>
<p>If the file is nout found then its' also searched into the directory of the last loaded template, or the last loaded subtemplate. <br>
<span class="versioning">Since TBS version 3.3.0</span>, the file also searched into the <a href="http://www.php.net/manual/en/ini.core.php#ini.include-path">include_path</a>.</p>
<h4>Adding the file at the end of the current template:</h4>
<p>You can use the keyword <span class="opt-value">'+'</span> for the argument <span class="opt-name">Charset</span> to have the file defined by <span class="opt-name">File</span> added to the end of the current template. The current charset will not be modified.</p>
<h4>Special actions using argument File:</h4>
<p><span class="versioning">Since TBS version 3.4.0.<br>
</span> If <span class="opt-name">File</span> is <span class="opt-value">null</span>, then all default actions (Plug-ins, [onload] tags, and Charset) are applied without loading any file. <br>
If <span class="opt-name">File</span> is <span class="opt-value">''</span> (empty string), then only the <a href="#php_setoption_charset" class="opt-name">charset</a> option is modified, without doing any other action. (deprecated since TBS version 3.8.0, use <a href="#php_setoption">SetOption()</a> instead)<br>
In both cases, if <span class="opt-name">Charset</span> is <span class="opt-value">'+'</span>, then it will be ignored and the current charset will not be modified.</p>
<p> Example:</p>
<pre class="decal txt-code"><span class="opt-name">$TBS</span>->Source = <span class="opt-name">$template</span>; <span class="opt-html">// load the template from a string</span>
<span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-value">null</span>,<span class="opt-value">'BIG5'</span>); <span class="opt-html">// run plug-ins if any, and merges [onload] tags if any</span>
...
<span class="opt-name">$TBS</span>->LoadTemplate(<span class="opt-value">''</span>,<span class="opt-value">false</span>); <span class="opt-html">// turn the charset to no-charset</span></pre>
</div>
<h3><a name="php_mergeblock" id="php_mergeblock"></a>method MergeBlock():</h3>
<div class="norm">
<p>Merges one or several <a href="#html_block">TBS blocks</a> with records coming from a data source.
By default, this method returns the number of merged records (more exactly, it is the number of the last record), but it can also return the full merged record set (see argument <span class="opt-name">BlockName</span>). </p>
<p>TinyButStrong supports several data source types in native:</p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th>Php data:</th>
<td>an array, a string, a number</td>
</tr>
<tr>
<th width="80">Databases:</th>
<td>MySQL ; PostgreSQL ; SQLite</td>
</tr>
</table>
<p> You can also add a new one: '<a href="#plugins_db">database plug-ins</a>'.</p>
<p> Syntax: <span class="txt-code"><span class="opt-type">int</span><span class="opt-name"></span> <span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-type">string</span><span class="opt-name"> BlockName</span>, <span class="opt-type">mixed</span> <span class="opt-name">Source<span style="color:#333333">{</span></span>, <span class="opt-type">string</span><span class="opt-name"> Query<span style="color:#333333">}{, <span class="opt-type">mixed</span> QryPrms}</span></span>)</span> </p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">BlockName</td>
<td align="left" valign="top">Indicates the name of the TBS <a href="#html_block">block</a> to merge.<br>
You can merge several blocks with the same data by indicating their names separated by commas. If you add <span class="opt-value"> '*'</span> as a block name, then the method will return the full merged record set as a PHP array, instead of the number of records.
<div class="versioning">Versioning: the keyword '*' is supported since TBS version 3.0.</div></td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">Source</td>
<td align="left" valign="top"><p>Indicates the data source to merge.<br>
The table below shows the possible values according to the data source type.</p></td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">Query</td>
<td align="left" valign="top"> Optional. Indicates the SQL statement which returns the records to merge.<br>
The table below shows the possible values according to the data source type.</td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">QryPrms</td>
<td align="left" valign="top">Optional. Extra parameters for the query. Few data source types are taking this argument in account.<br>
<div class="versioning">Versioning: the argument QryPrms is supported since TBS version 3.7.0.</div></td>
</tr>
</table>
<h4>Link between the block and the records:</h4>
<div class="decal">
<p>The MergeBlock() method searches in your template for the specified TBS block name. Then, the block is repeated as many times as there are records in the data source. </p>
<p> To display the data of a record, you have to use a linked TBS Field. A TBS Field is linked when the name of it is composed of the block's name followed by a dot and a column's or a key's name in the record set. A linked field must be inside the block.</p>
<p> Example: </p>
<div class="decal"> Block's name: <span class="opt-value">block1</span><br>
Columns returned by the query: <span class="opt-value">field1</span>,<span class="opt-value">field2</span>,<span class="opt-value">field3</span><br>
Linked TBS Fields: <span class="opt-value"> [block1.field1]</span>, <span class="opt-value">[block1.field2]</span>, <span class="opt-value">[block1.field3]</span></div>
<p>If no block's definition is found in the template, then the MergeBlock() method will merge the first record with all linked fields found in the template.</p>
<p> You can also define more advanced blocks. For more information, refer to chapter <a href="#html_block">TBS Blocks</a>.</p>
</div>
<h4><a name="php_mergeblock_mergeseveral" id="php_mergeblock_mergeseveral"></a>Merging several blocks with the same data:</h4>
<div class="decal">
<p>You can merge several blocks with the same data by indicating their names separated by commas in the <span class="opt-name">BlockName</span> parameter. In this case, the query is opened only one time, and records are buffered to feed blocks.</p>
<p> Example: <span class="opt-name"><span class="txt-code">$TBS</span></span><span class="txt-code">->MergeBlock(<span class="opt-value">'block1,block2,block3'</span>,<span class="opt-value">'mysql'</span>,<span class="opt-value">'SELECT * FROM MyTable'</span>);</span></p>
<p> You cannot merge several blocks having the same names because
they are considered by TBS has a one and only block composed of several sections. Nevertheless, you can use a tip to get a similar behavior. If you use parameter <a href="#html_block_prm_p1" class="opt-name">p1</a> without value in the block definition, that does forces TBS to consider the section as a new block break, like it does for <a href="#html_block_dynsb">subblocks</a>.</p>
<p> Example: </p>
<div class="decal">
<table border="0" cellspacing="5" cellpadding="0">
<tr>
<td><table border="1" cellspacing="0" cellpadding="1">
<tr style="font-weight:bold; background-color: #66CCFF;">
<td>Id</td>
<td>Name</td>
</tr>
<tr>
<td>[b.id;block=tr;p1]</td>
<td>[b.name]</td>
</tr>
</table></td>
<td><table border="1" cellspacing="0" cellpadding="1">
<tr style="font-weight:bold; background-color: #FFCC66;">
<td>Id</td>
<td>Name</td>
</tr>
<tr>
<td>[b.id;block=tr;p1]</td>
<td>[b.name]</td>
</tr>
</table></td>
</tr>
</table>
<p class="txt-code"><span class="opt-name"><span class="txt-code">$TBS</span></span>->MergeBlock(<span class="opt-value">'b'</span>,<span class="opt-value">'mysql'</span>,<span class="opt-value">'SELECT * FROM MyTable'</span>);</p>
</div>
<p class="versioning">Versioning: this tip is available since TBS version 3.4. </p>
</div>
<h4>Returning the full merged record set:</h4>
<div class="decal">
<p>In some cases, it may be useful for you to retrieve the full record set after the merge. For that, you simply have to ad the keyword <span class="opt-value">'*'</span> in the list of block's names. Use this feature with care, because it save the merged data in the memory which can take resources.</p>
<p> Example: <span class="opt-name">$data</span> = <span class="opt-name"><span class="txt-code">$TBS</span></span><span class="txt-code">->MergeBlock(<span class="opt-value">'block1,*'</span>,<span class="opt-value">'mysql'</span>,<span class="opt-value">'SELECT * FROM MaTable'</span>);</span></p>
</div>
<h4><a name="php_mergeblock_counting"></a>Counting the records:</h4>
<div class="decal">
<p>To display the number of the record in the template, use a TBS Field linked to the virtual column '<span class="opt-value">#'</span>.
If you put this field outside the block, it will display the total number of records.</p>
<p> Example: <span class="opt-value">[block1.#]</span></p>
<p> The virtual column '<span class="opt-value">$'</span> will display the key of the current record if the data source is a Php array.</p>
<p> Example: <span class="opt-value">[block1.$]</span></p>
</div>
<h4>Resource and Request arguments according to the data source type:</h4>
<div class="decal">
<table cellpadding="2" cellspacing="0" class="border-0">
<tr style="font-weight:bold; background-color: #B2B2B2;">
<td width="120" class="border-0">Data Source Type</td>
<td width="350" class="border-0">Source</td>
<td class="border-0">Query<span class="txt-code"><span class="opt-name"></span></span></td>
</tr>
<tr valign="top">
<td class="border-0">Assigned <span class="txt-tiny">(*)</span></td>
<td class="border-0">The keyword <span class="opt-value">'assigned'</span> or omitted</td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td class="border-0">Text <span class="txt-tiny">(*)</span></td>
<td class="border-0">The keyword <span class="opt-value">'text'</span></td>
<td class="border-0">A text</td>
</tr>
<tr valign="top">
<td class="border-0">Number <span class="txt-tiny">(*)</span></td>
<td class="border-0">The keyword <span class="opt-value">'num'</span></td>
<td class="border-0">A number or a special array (see below)</td>
</tr>
<tr valign="top">
<td class="border-0">Clear<span class="txt-tiny"> (*)</span></td>
<td class="border-0">The keyword <span class="opt-value">'clear'</span></td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td class="border-0">Conditional<span class="txt-tiny"> (*)</span></td>
<td class="border-0">The keyword <span class="opt-value">'cond'</span></td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td rowspan="3" class="border-0"> PHP Array <span class="txt-tiny">(*)</span></td>
<td class="border-0">A Php array</td>
<td class="border-0">-</td>
</tr>
<tr>
<td valign="top" class="border-0">The keyword <span class="opt-value">'array'</span></td>
<td valign="top" class="border-0">A Php Array</td>
</tr>
<tr>
<td valign="top" class="border-0">The keyword <span class="opt-value">'array'</span></td>
<td valign="top" class="border-0">A string that represents an array contained or nested in a PHP global variable (see below)</td>
</tr>
<tr>
<td class="border-0">PHP <a href="http://www.php.net/manual/en/class.arrayobject.php">ArrayObject</a></td>
<td rowspan="3" valign="top" class="border-0">A PHP object. <span class="versioning">Supported since TBS version 3.5.0.</span></td>
<td rowspan="3" valign="top" class="border-0">-</td>
</tr>
<tr>
<td class="border-0">PHP <a href="http://www.php.net/manual/en/class.iterator.php">Iterator</a></td>
</tr>
<tr>
<td class="border-0">PHP <a href="http://www.php.net/manual/en/class.iteratoraggregate.php">IteratorAggregate</a></td>
</tr>
<tr valign="top">
<td class="border-0">PDO</td>
<td class="border-0">A <a href="http://www.php.net/manual/en/book.pdo.php">PDO</a> object. <span class="versioning">Supported since TBS version 3.7.0.</span></td>
<td class="border-0">An SQL statement. Optional argument <a href="#php_mergeblock" class="opt-name">QryPrms</a> can be used like with <a href="http://www.php.net/manual/en/pdostatement.execute.php">PDOStatement->execute(QryPrms</a>).</td>
</tr>
<tr valign="top">
<td class="border-0">Zend DB Adapter</td>
<td class="border-0">A <a href="http://framework.zend.com/manual/en/zend.db.adapter.html">Zend DB Adapter</a> object. <span class="versioning">Supported since TBS version 3.8.0.</span></td>
<td class="border-0">An SQL statement. Optional argument <a href="#php_mergeblock" class="opt-name">QryPrms</a> can be used like with <a href="http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.transactions">$db->execute($sql, $prms</a>).</td>
</tr>
<tr valign="top">
<td class="border-0">MySQLi</td>
<td class="border-0">A <a href="http://www.php.net/manual/en/book.mysqli.php">MySQLi</a> object. <span class="versioning">Supported since TBS version 3.7.0.</span></td>
<td class="border-0">An SQL statement</td>
</tr>
<tr valign="top">
<td rowspan="2" class="border-0">MySQL</td>
<td class="border-0">A <a href="http://www.php.net/manual/en/book.mysql.php">MySql</a> connection identifier or the keyword <span class="opt-value">'mysql'</span></td>
<td class="border-0">An SQL statement</td>
</tr>
<tr>
<td class="border-0">A MySql result identifier</td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td rowspan="2" class="border-0">PostgreSQL</td>
<td class="border-0">A <a href="http://www.php.net/manual/en/book.pgsql.php">PostgreSql</a> connection identifier</td>
<td class="border-0">An SQL statement</td>
</tr>
<tr>
<td class="border-0">A PostgreSql result identifier</td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td rowspan="2" class="border-0">SQLite</td>
<td class="border-0">An <a href="http://www.php.net/manual/en/book.sqlite.php">SQLite</a> connection identifier</td>
<td class="border-0">An SQLite statement</td>
</tr>
<tr>
<td class="border-0">An SQLite result identifier</td>
<td class="border-0">-</td>
</tr>
<tr valign="top">
<td class="border-0">custom<br></td>
<td class="border-0">A keyword, an object or a resource identifier not mentioned in this table.<br>
See the chapter '<a href="#plugins_db">database plug-ins</a>'.</td>
<td class="border-0">An SQL statement or something else.</td>
</tr>
</table>
<p class="txt-tiny">(*) See explanations in the chapter below.</p>
</div>
<h4>Php data sources:</h4>
<div class="decal">
<h5>• Assigned</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be equal to <span class="opt-value">'assigned'</span> or be omitted.
The block is merged with the arguments defined in the property <a href="#php_assigned">Assigned</a>. </p>
<p> Example : <span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b1'</span>);</span></p>
<p class="versioning">Versioning: the keyword 'assigned' is supported since TBS version 3.5. </p>
</div>
<h5>• Text</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be equal to <span class="opt-value">'text'</span>.
The whole block is replaced by the text (it must be a string) given as the <span class="opt-name">Query</span> argument. No linked Fields are processed except '<span class="opt-value">#'</span> which returns 1, or 0 if <span class="opt-name">Query</span> is an empty string. </p>
<p> Example: <span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b1'</span>,<span class="opt-value">'text'</span>,<span class="opt-value">'Hello, how are you?'</span>); </span></p>
</div>
<h5> • Number</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be equal to <span class="opt-value"></span> <span class="opt-value">'num'</span>.
The argument <span class="opt-name">Query</span> can be either a number or an array. </p>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<th>arg Query</th>
<th>Returned Record Set</th>
</tr>
<tr>
<td valign="top">Number:</td>
<td>This number has to be positive or equal to zero. The returned Record Set consists of a column <span class="opt-value">'val'</span> where the value goes from 1 to this number.</td>
</tr>
<tr>
<td valign="top">Array:</td>
<td>This array has to contain a key <span class="opt-value">'min'</span> and a key <span class="opt-value">'max'</span> and eventually a key <span class="opt-value">'step'</span>.<br>
The returned Record Set consists of a column <span class="opt-value">'val'</span> which goes from the <span class="opt-value">'min'</span> value to the <span class="opt-value">'max'</span> value.</td>
</tr>
</table>
<p>Examples:</p>
<pre class="decal"><span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b1'</span>,<span class="opt-value">'num'</span>,<span class="opt-value">12</span>);</span>
<span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b2'</span>,<span class="opt-value">'num'</span>,array(<span class="opt-value">'min'</span>=><span class="opt-value">20</span>,<span class="opt-value">'max'</span>=>3<span class="opt-value">0</span>));</span>
<span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b3'</span>,<span class="opt-value">'num'</span>,array(<span class="opt-value">'min'</span>=><span class="opt-value">10</span>,<span class="opt-value">'max'</span>=><span class="opt-value">20</span>,<span class="opt-value">'step'</span>=><span class="opt-value">2</span>));</span></pre>
</div>
<h5>• Clear</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be the keyword <span class="opt-value">'clear'</span>.
All blocks and sections are deleted. It is the same thing as merging with an empty array. </p>
<p> Example: <span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'b1'</span>,<span class="opt-value">'clear'</span>); </span></p>
</div>
<h5>• Conditional</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be the keyword<span class="opt-value">'cond'</span>.
The block is merged like it was a <span class="opt-name"> <a href="#html_conditional_section">conditional blocks</a> onload</span> and <span class="opt-name">onshow</span>. The block is not merged with data, and so it must have no linked TBS field. Each block section needs a parameter <span class="opt-name">when</span> or a parameter <span class="opt-name">default</span>. See <a href="#html_conditional_section">conditional blocks</a> for more details. </p>
<p> Example: <span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'bz'</span>,<span class="opt-value">'cond'</span>);</span></p>
</div>
<h5>• Array</h5>
<div class="decal">
<p>The argument <span class="opt-name">Source</span> has to be a PHP Array or the keyword <span class="opt-value">'array'</span>. If you use the keyword <span class="opt-value">'array'</span>, then the argument <span class="opt-name">Query</span> has to be a Php Array or a string that represents an array contained or nested in a global variable.</p>
<p> String syntax: <span class="opt-value">'globvar[item1][item2]...'</span></p>
<p>'globvar' is the name of a global variable $globvar which must be an array.<br>
'item1' and 'item2' are the keys of an item or a subitem of $globvar. </p>
<p> Example: </p>
<pre class="decal txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'block1'</span>,<span class="opt-value">'array'</span>,<span class="opt-value">'days[mon]'</span>);</pre>
<div class="decal txt-small">This will merge 'block1' with the value $day['mon'] assuming it is an array. </div>
<p>It is possible to represent variable's name without items.</p>
<p> Example: </p>
<pre class="decal"> <span class="txt-code"><span class="opt-name">$TBS</span>->MergeBlock(<span class="opt-value">'block1'</span>,<span class="opt-value">'array'</span>,<span class="opt-value">'days'</span>);</span></pre>
<p>There are two advantages in using a string to represent the array:</p>
<ul>
<li> Items will be read directly in the Array (assigned by reference) instead of reading a copy of the items. This can improve the performance.</li>
<li> You can use dynamic queries. </li>
</ul>
<h6>Displaying the key of current record:</h6>
<p>You can use the virtual column '<span class="opt-value">$'</span> which will display the key of the current record. This can be useful especially for <a href="#html_block_dynsb">subblocks with dynamic queries</a>. </p>
<p>Example: [block1.$]</p>
<h6>Structure of supported arrays: </h6>
<p> Items of the specified Array can be of two kinds: simple values with associated keys (case 1), or array values for whom items are themselves simple values with associated keys (case 2).</p>
<p> Case 1: </p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="80" valign="top">Example: </td>
<td valign="top"><pre>['key1']=>value1
['key2']=>value2
...</pre></td>
</tr>
</table>
<p>The returned Record Set consists of a column <span class="opt-value">'key'</span> containing the name of the key, and a column <span class="opt-value">'val'</span> containing the value of the key. </p>
<p> Case 2: </p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="80" valign="top">Example: </td>
<td valign="top"><pre>[0] => (['column1']=>value1-0 ; ['column2']=>value2-0 ; ...)
[1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...)
[2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...)
...</pre></td>
</tr>
</table>
<p>The returned Record Set consists of the columns <span class="opt-value">'column1'</span>, <span class="opt-value">'column2'</span>,... with their associated values. </p>
</div>
</div>
</div>
<h3><a name="php_show" id="php_show"></a>method Show():</h3>
<div class="norm">
<p>Terminates the merge. </p>
<p> Syntax: <span class="txt-code"><span class="opt-name">$TBS</span>->Show(<span class="opt-name"><span style="color:#333333">{</span></span><span class="opt-type">int</span><span class="opt-name"> </span><span class="opt-name">Render</span><span class="opt-name"></span><span class="opt-name"><span style="color:#333333">}</span></span>)</span></p>
<p> The Show() method performs the following actions:</p>
<ol>
<li> Merge [onshow] <a href="#html_field_auto">fields</a> and <a href="#html_block_auto">blocks</a>,</li>
<li>Merge [var] <a href="#html_field_auto">fields</a> (for compatibility with version prior to 3.2.0), </li>
<li> Display the result (this action can be cancelled by defining another <a href="#php_setoption_render">Render</a> in the options or in the argument),</li>
<li> End the script (this action can be cancelled by defining another <a href="#php_setoption_render">Render</a> in the options or in the argument).</li>
</ol>
<p> The <a href="#php_setoption_render">Render</a> allows to adjust the behavior of the Show() method. See the <a href="#php_setoption_render">Render</a> option for more information.</p>
</div>
<h3><a name="php_getblocksource" id="php_getblocksource"></a>method GetBlockSource():</h3>
<div class="norm">
<p>Returns the source of a TBS Block from the template.
If no block is found, the method returns <span class="txt-code"><em><span style="color:#0033CC">false</span></em></span>.</p>
<p> Syntax: <span class="txt-code"><span class="opt-type">string</span> <span class="opt-name"></span><span class="opt-name">$TBS</span>->GetBlockSource(<span class="opt-type">string </span><span class="opt-name">BlockName </span>{,<span class="opt-type"> boolean</span> <span class="opt-name">AsArray</span>}{,<span class="opt-type"> boolean</span> <span class="opt-name">DefTags</span>}{,<span class="opt-type"> mix</span> <span class="opt-name">ReplaceWith</span>})</span></p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">BlockName</td>
<td align="left" valign="top">The name of the block to search for.<br></td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">AsArray</td>
<td align="left" valign="top">Optional. The default value is <span class="txt-code"><em><span style="color:#0033CC">false</span></em></span>. If this parameter is <span class="txt-code"><em><span style="color:#0033CC">true</span></em></span> the method returns the source of the block as a PHP array instead of a string. If the result is an array, then each sections of the block is saved as an item. First item is index 1.</td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">DefTags</td>
<td align="left" valign="top">Optional. The default value is<span class="txt-code"><em><span style="color:#0033CC"> true</span></em></span>. By default, the method GetBlockSource() returns the source of the block including its definition tags. If you'd like those tags to be deleted, then force the argument <span class="opt-name">DefTags</span> to <em><span style="color:#0033CC">false</span></em>. If the block is defined with a <a href="#html_block">simplified syntax</a> then the definition tags will not be deleted anyway because they are also Field tags.<br>
<p class="versioning">Versioning: this argument is supported since TBS version 3.0.</p></td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">ReplaceWith</td>
<td align="left" valign="top">Optional. Default value is <em><span style="color:#0033CC">false</span></em>. If this argument is a string then
the block source is replaced with it in the template. You can use <span class="opt-name">ReplaceWith</span> = <span class="opt-value">''</span> (empty string) in order to delete the block source from the template.<br>
<p class="versioning">Versioning: this argument is supported since TBS version 3.05.</p></td>
</tr>
</table>
<span class="txt-code"> </span><br>
This method enables you to get the source of a block in order to manually handle the merging.<br>
After that, if you need to replace the block with text, you can use the <a href="#php_mergeblock">MergeBlock()</a> method with the '<span class="opt-value">text</span>' parameter.<br>
<div class="versioning">
<p>Versioning:</p>
<ul class="list-mini">
<li> Since TBS 3.05 if <span class="opt-name">AsArray</span> is <span class="opt-type">false</span> then the method returns block with all its sections. Before TBS 3.05 it return only the first section.</li>
<li>Since TBS 3.05 if <span class="opt-name">AsArray</span> is <span class="opt-type">true</span> and the block is not found then the method returns <span class="opt-type">false</span>. Before TBS 3.05 it return an empty Array.</li>
</ul>
</div>
</div>
<h3><a name="php_mergefield" id="php_mergefield"></a>method MergeField():</h3>
<div class="norm">
<p>Replaces one or several TBS Fields with a fixed value or by calling a user function. Each TBS fields having the specified base name will be merged. </p>
<p> Since TBS version 3.0, it's also possible to indicate a method of a class (see <a href="#php_oop">OOP</a>).</p>
<p> It is also possible to merge the special [onload], [onshow] and [var] (see below).</p>
<p> Syntax: <span class="txt-code"><span class="opt-name">$TBS</span>->MergeField(<span class="opt-type">string </span><span class="opt-name">BaseName</span>,<span class="opt-type"> mixed</span></span><span class="txt-code"> <span class="opt-name">X</span><span class="opt-name"> </span>{,<span class="opt-type"> boolean</span> <span class="opt-name">FunctionMode</span>}{, <span class="opt-type">array</span> <span class="opt-name">DefaultPrm</span>})</span> </p>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">BaseName</td>
<td align="left" valign="top">Base name of the TBS Fields. For example <span class="opt-value">'account'</span>.</td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">X</td>
<td align="left" valign="top">The value to display (or a string that represent the name of a user function if the argument <span class="opt-name">FunctionMode</span> is set to <span class="opt-value">true</span>).</td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">FunctionMode</td>
<td align="left" valign="top">Indicates that the value to display is calculated by a user function. The default value is <span class="opt-value">false</span>. If this argument is set to <span class="opt-value">true</span>, then <span class="opt-name">X</span> must be a text string giving the name of the user function. This function must exist and have the syntax described below.</td>
</tr>
<tr>
<td align="left" valign="top" class="opt-name">DefaultPrm</td>
<td align="left" valign="top"><p>List of parameters to apply by default to the merged fields. Parameters have to be given as an associative PHP array. If a parameter is defined in both argument DefaultPrm and in the field, then the parameter of the field will be taken in account.<br>
<span class="versioning">This argument is supported since TBS version 3.5.0.</span><br>
</p></td>
</tr>
</table>
<h4>Merging with a value:</h4>
<p><span class="opt-name">X</span> can be numeric, string, an array or an object. For an array or an object, names of TBS Fields must have suffixes like <a href="#html_field_auto">automatic fields ([onload] and [onshow])</a>.</p>
<p> Example: </p>
<pre class="decal txt-code"><span class="opt-name">$TBS-></span>MergeField(<span class="opt-value">'account'</span>,array(<span class="opt-value">'id'</span>=><span class="opt-value">55</span>,<span class="opt-value">'name'</span>=><span class="opt-value">'Bob'</span>));</pre>
<div class="decal txt-small">In this example, the fields <span class="opt-value"></span>[account.id] and [account.name] will be merged.</div>
<h4>Merging with a user function:</h4>
<p>TBS calls this function for each field found in the template. <br>
This function must have the following syntax: </p>
<pre class="decal txt-code">function fct_user(<span class="opt-name">$Subname</span> [, <span class="opt-name">$PrmLst</span>]) {...}</pre>
<p>When the function is called, its argument <span class="opt-name">$Subname</span> has for value the suffix of the field's name (example: for a field named <span class="opt-value">'ml.title'</span>, <span class="opt-name">$Subname</span> will have the value <span class="opt-value">'title')</span>. And the optional argument <span class="opt-name">$PrmLst</span> contains an associative array with the field's parameters. The function must return the value to be merged. </p>
<p> Example: </p>
<pre class="decal txt-code"><span class="opt-name">$TBS-></span>MergeField(<span class="opt-value">'ml'</span>,<span class="opt-value">'m_multilanguage'</span>,<span class="opt-value">true</span>);
...
function m_multilanguage(<span class="opt-name">$Subname</span>) {
global <span class="opt-name">$lang_id</span>;
<span class="opt-name">$rs</span> = mysql_query(<span class="opt-value">"SELECT text_$lang_id AS txt FROM t_language WHERE key='$Subname"</span>);
<span class="opt-name">$rec</span> = mysql_fetch_array(<span class="opt-name">$rs</span>);
return <span class="opt-name">$rec</span>[<span class="opt-value">'txt'</span>] ;
}</pre>
<div class="decal txt-small">In this example, a field such as <span class="opt-value">[ml.title]</span> will be merged with the value returned by <span class="opt-value">m_multilanguage('title')</span>.</div>
<h4>Merge automatic fields and blocks:</h4>
<p>You can use the method MergeField() in order to force the merge of the automatic <a href="#html_field_auto">fields</a> and <a href="#html_block_auto">blocks</a> ([onload] and [onshow]). But in this case, only the first argument should be indicated.</p>
<p> Example: <span class="txt-code"><span class="opt-name">$TBS-></span>MergeField(<span class="opt-value">'var'</span>); </span> </p>
<p class="versioning">Versioning: the merge of special automatic fields is supported since TBS version 3.0. It replaces the old method MergeSpecial() which is not supported anymore. </p>
</div>
<h3><a name="php_setoption" id="php_setoption"></a>Method SetOption():</h3>
<div class="norm">
<p>Set one or several TBS options. See the list and desciptions of options below.<br>
Some of the TBS options are a new way of setting <a href="#php_options_compatibility">old TBS features</a>. </p>
<p class="versioning">Versioning: methods <span class="opt-name">SetOption()</span> is supported since TBS version 3.8.0. </p>
<h4> Syntax:</h4>
<p class="decal"> <span class="txt-code"><span class="opt-name">$TBS</span>->SetOption(<span class="opt-type"><span class="opt-value">string</span></span> $option_name, <span class="opt-type">mixed</span> $value)</span></p>