Login   Register  
PHP Classes
elePHPant
Icontem

File: QuickTemplate.html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Stefan Bocskai  >  QuickTemplate  >  QuickTemplate.html  >  Download  
File: QuickTemplate.html
Role: ???
Content type: text/plain
Description: Documentation V2.3
Class: QuickTemplate
Author: By
Last change:
Date: 2001-08-30 12:03
Size: 27,930 bytes
 

Contents

Class file image Download
<html>
<body text="#000080" bgcolor="#ffffff">
<center>
<h1>QuickTemplate</h1>
<h3>Version 2.3</h3>
<b><i>this version has some <a href="#restriction">restrictions</a> for php4.0.4pl1!</i></b><br>
<i>Author: 
Stefan Bocskai <a href="mailto:stefanbocskai@hotmail.com">&lt;stefanbocskai@hotmail.com&gt;</a></i><br>
<i>Romania, 
Cluj-Napoca / France, Paris - August 2001</i> 
</center>
<hr>
<br>

<h2><u>ABOUT</u></h2>

<p>
<b><i>QuickTemplate</i></b> is a PHP extension for mananging templates and 
performing multi level variable and block interpolation.   
</p>

<p><b>What is a template?</b><br>
A template is a text file in html format (or other). The 
templates are very usefull because you can define dynamic parts of a page by 
blocks and sub-blocks. So, for example, you could create tables with multiple 
rows by defining the row as a block. These blocks accept variables defined by 
user or predefined (as the current time or date), which are interpolated in the 
context of the block when the block is parsed. 
</p>

<p><b>Why QuickTemplate ?</b><br>
QuickTemplate class can manage a <b>multi-level template</b>. So, you can define blocks and multi-level nested 
blocks. There is a real objectual structure of the blocks. You must specify the 
root of the template (the block that contains the others blocks), but it's not 
necessary to be the top level block of the template. You can choose other (lower 
level) block as the root of the template, and the parsing is started from this 
point.<br>
<b>Multi-level variables</b> 
can be defined by the user. A variable like {MYDATA.NAME} or {MYDATA.AGE} means 
that with &quot;MYDATA&quot; is associated an array with the keys 
&quot;NAME&quot; or &quot;AGE&quot; etc.. But there are no limits to the number 
of levels.<br>
Some <b>defaults 
variables</b> are defined: like date, time, self url, auto-increment etc. 
</p>

<p>
<a name="restriction"></a>
<b><FONT face="" size=5>&sect; What's new in V2.3?</b> </FONT> <br>

Some bugs are fixed, now working on PHP >= 4.0.4! <br>
For PHP version 4.0.4pl1 are some bugs, so <b>is not recomanded</b> to use with this version if your 
templates file size is greater than 10k! cause of bug(?) in regex functions of this version of php!

</p><B></B><B></B>
<p><b><FONT face="" size=5>&sect; What's new in V2.1?</b> </FONT> <br>
Your 
scripts are faster using the <b><FONT face=Courier>AssignLocal </FONT></b>method.<br>
Some 
bugs are fixed, now working on PHP4.0.3! <br>
You can insert 
now a file using the tag: <font face="Courier">{HTML_SOURCE:url}</font> directly in 
template. 

</p>
<p>&nbsp; 
</p>


<h2><u>Public functions</u></h2>

<p>
<b><font size=+1>Constructor :</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>function 
QuickTemplate($misc, $part=&quot;main&quot;, $flag=0) 
</font>
<br>
<blockquote>
 <b>Description:</b>
   <blockquote>
    The constructor of the class. This 
        function creates an instance of the class and initialises the 
        incapsulated data. For <i>external use</i> do not 
        use the flag <i>flag</i>, this flag is used in <i>internal call</i> of the function. 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$misc</b> (<i>string</i>)<br>
     The name of the 
        template (text file) which need to be parsed.<br><br>
     <b>$part</b> (<i>string</i>)<br>
     The first block of the template, 
        the <b>root</b> of the block's structure. It's not 
        necessary to be the first level block. The template is parsed begining 
        from this block. If not sent the default value is <i>&quot;main&quot;</i><br><br>
     <b>$flag</b><br>
     Not used. 
        (For internal use only)
   </blockquote>
</blockquote>
<blockquote>
 <b>Returned value:</b>
   <blockquote>
    As a constructor, returns nothing :-(^) 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Example:</b>
   <blockquote>
    <font face="arial"> 
    $tpl = new QuickTemplate(&quot;./templates/main.tpl&quot;, 
        &quot;main&quot;); 
 
    </font>
   </blockquote>
</blockquote>
<P></P>



<p>
<b><font size=+1>Assignements :</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>function 
Assign($name, $val) 
</font>
<br>
or<br>
<font face="courier" color="#000000" size=+1>function 
Assign($name) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
    There are two ways to assign a value to 
        the varioable that apperas in the template.<b>First</b>,by specifying the name and the value as arguments of the 
        function. The value could be a simple value or an array (see ex. 1). 
    <br>The <b>second</b> way is to 
        specifyng as a single argument of the this function an assciative array 
        (see ex. 2). The result is the same as making more simple assignements. 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$name</b> (<i>string</i>)<br>
     The name of the 
        variable that appears in the template or an associative array.<br><br>
     <b>$val</b> (<i>string / array</i>)<br>
     This value must be specified if the first argument <i>$name</i> is not an associative array. If this is 
        a simple value (string) the name $name is associated with this value. If 
        this argument is an associative array, a complex association is made 
        (see ex. 3). 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Returned value:</b>
   <blockquote>
    Nothing to return. :-(^) 
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <b>example 1:</b>
     <font face="arial"> 
     $tpl-&gt;Assign(&quot;TITLE_OF_PAGE&quot;,&quot;First 
        Example&quot;);
     </font><br>
     <b>example 2:</b>
     <font face="arial">
     $tpl-&gt;Assign(array(&quot;TITLE_OF_PAGE&quot; =&gt; &quot;Second 
        examle&quot;,&quot;MY_NAME&quot; =&gt; &quot;John Smith&quot;)); 
 
     </font><br>
     <b>example 3:</b>
     <font face="arial">                           
     $tpl-&gt;Assign(&quot;FULL_NAME&quot;, array(&quot;FIRST_NAME&quot; 
        =&gt; &quot;John&quot;, &quot;LAST_NAME&quot; =&gt; &quot;Smith&quot;)); 
 
     </font><br><br>
      In the last 
        example the variables that should appear in the template are: 
        {FULL_NAME.FIRST_NAME} or {FULL_NAME.LAST_NAME}. (See <b>variables</b> for more information)
     
   </blockquote>
</blockquote><br>
<font face="courier" color="#000000" size=+1>function AssignLocal($part, $name, $val) 
</font>
<br>
or<br>
<font face="courier" color="#000000" size=+1>function AssignLocal($part, $name) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
    See <FONT color=#000000 face=Courier 
        size=4><STRONG>Assign</FONT> 
        </STRONG>function. Difference betwen Assign and AssignLocal is that the 
        last function doesn't perfrm a recursive assign, the variables are 
        asigned just in the specified block. Now your scripts are <STRONG>faster</STRONG> than a rocket :-) 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b></b>
     <b>$part</b> (<i>string</i>)<br>
     The name of the block where you want to make the 
        assign.<br> 
 
   </blockquote>
   <blockquote>
     <b>$name</b> (<i>string</i>)<br>
     The name of the 
        variable that appears in the template or an associative array.<br><br>
     <b>$val</b> (<i>string / array</i>)<br>
     This value must be specified if the first argument <i>$name</i> is not an associative array. If this is 
        a simple value (string) the name $name is associated with this value. If 
        this argument is an associative array, a complex association is made 
        (see ex.). 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Returned value:</b>
   <blockquote>
    Nothing to return. :-(^) 
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <b>example 1:</b>
     <font face="arial"> 
     $tpl-&gt;AssignLocal(&quot;main.table.row&quot;, 
        &quot;STUDENT_NAME&quot;, &quot;Smith&quot;);
     </font><br>&nbsp;
     
   </blockquote>
</blockquote>
<P></P>



<p>
<b><font size=+1>Null strings and blocks:</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>
function SetNullString($nullstring) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
    With this function you can set the 
        String that will appear if any variable is empty. You can set the 
        &quot;NullString&quot; runtime as &quot;Empty value&quot;, 
        &quot;0.00%&quot;, &quot;&amp;nbsp;&quot; or &quot;&quot;; 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$nullstring</b> 
        (<i>string</i>)<br>
     Any string 
        that you want.
   </blockquote>
</blockquote>
<blockquote>
 <b>Returned value:</b>
   <blockquote>
    Nothing to return. :-(^) 
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     $tpl-&gt;SetNullString(&quot;&quot;);<br>                      
     $tpl-&gt;SetNullString(&quot;0&quot;);<br>
     $tpl-&gt;SetNullString(&quot;0.00%&quot;);<br>
     $tpl-&gt;SetNullString(&quot;Empty value&quot;);<br>
     $tpl-&gt;SetNullString(&quot;&amp;nbsp;&quot;);<br>
     </font>
   </blockquote>
</blockquote>
<P></P>





<p>
<br><br>
<font face="courier" color="#000000" size=+1>
function 
DefaultBlockValue($part, $value=&quot;&amp;nbsp;&quot;) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
    You can set the text that you want to 
        appear if a block of template is not parsed, is cleared or is empty. 
   
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     This is a 
        refernce to a block. (see <b>Block Reference</b> for 
        more info.)<br>
     <b>$value</b> (<i>string</i>)<br>
     The text that 
        will appear if the conntent of block is empty. 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Returned value:</b>
   <blockquote>
    Nothing to return. :-(^) 
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     $tpl-&gt;DefaultBlockValue(&quot;main.table.rows&quot;, &quot;There 
        are no rows!&quot;);<br>
     </font>
   </blockquote>
</blockquote>
<P></P>




<p>
<b><font size=+1>Resetting the blocks:</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>
function 
Reset($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   This function sets to empty the text 
        associated with a block; There's no need to Reset a unparsed block. 
 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     $tpl-&gt;Reset(&quot;main.table.rows&quot;);<br>                      
     </font>
   </blockquote>
</blockquote>
<P></P>



<p>
<b><font size=+1>Auto-increment:</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>
function 
SetAutoincrement($part, $start_value, $increment=1) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   Sets the start value and the increment 
        value of the auto-increment variable of the block. (see <b>Defaults variables</b> for more details)
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)<br><br>
     <b>$start_value</b> (<i>integer</i>)<br>
     Value from which start the 
        incrementation of specified block. 
     <b>$increment</b> 
        (<i>integer</i>)<br>
     Value with 
        wich is incremented the auto-increment variable.
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     $tpl-&gt;SetAutoincrement(&quot;main.table.rows&quot;,1);</font><br>
     That means that the incrementation begin with 1 
        (each value encreased with 1 by default)<br><br>
     <font face="arial">     
     $tpl-&gt;SetAutoincrement(&quot;main.table.rows&quot;,0,100);</font><br>
     That means that the incrementation begin with 0 
        (each value encreased with 100)<br><br>
                                            
   </blockquote>
</blockquote>
<P></P>


<p>
<br><br>
<font face="courier" color="#000000" size=+1>
function 
GetAutoincrement($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   Gets the current value of the 
        incrementation. (see <b>Defaults variables</b> for 
        more details)
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)<br><br>
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     $increment_value = 
        $tpl-&gt;GetAutoincrement(&quot;main.table.rows&quot;);<br>                      
     </font>The function will return the current value of 
        incrementation for specified block.
   </blockquote>
</blockquote>
<P></P>




<p>
<b><font size=+1>Parse:</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>
function parse($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   This function replaces the current 
        values of the variables of a block, and the child blocks; the results 
        are stored into a value associated with the block (in append mode). 
        After parsing a block all of associated values of his child-blocks are 
        reseted. If any child-block has an empty value associated it is replaced 
        with the value set for this block by
   <i>DefaultBlockValue</i> function. Any other value from a block that 
        is not a child-block is replaced with the current setting of <i>NullString</i>
   <br><b>TODO: </b>a specific &quot;NullString&quot; for 
        every variable of the template. 
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     This example creates from a template a 
        page that contains two tables with 2 and 3 rows. 
     <font face="arial">     
      <br>... assignements ... <br>
     $tpl-&gt;parse(&quot;main.table.rows&quot;); //first 
        row of first table<br>
      ... assignements ... <br>
     $tpl-&gt;parse(&quot;main.table.rows&quot;); 
        //second row of first table<br>
 
     $tpl-&gt;parse(&quot;main.table&quot;); //parsing first table <br>

      ... assignements ... <br>
     $tpl-&gt;parse(&quot;main.table.rows&quot;); //firs row of second 
        table<br>
      ... assignements ... <br>
     $tpl-&gt;parse(&quot;main.table.rows&quot;); //second row of second 
        table<br>
      ... assignements ... <br>                                     
     $tpl-&gt;parse(&quot;main.table.rows&quot;); //third row of second 
        table<br>                                                   
                
     $tpl-&gt;parse(&quot;main.table&quot;); 
        //parsing second table <br> 


     $tpl-&gt;parse(&quot;main&quot;);<br>                      
     </font>
   </blockquote>
</blockquote>
<P></P>



<p>
<br><br>
<font face="courier" color="#000000" size=+1>
function Parsed($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   <b>Parsed</b> 
        returns <b>true</b> if the specified block was 
        already parsed, otherwise returns <b>false</b>. 
        Parse returns <b>false</b> if his parent was parsed 
        before the call of this function. Returns <b>false</b> if the block was reseted.
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)
   </blockquote>
</blockquote>
 <b>Returns:</b>
   <blockquote>
     The function returns <b>TRUE</b> or <b>FALSE</b>.
   </blockquote>
<BLOCKQUOTE></BLOCKQUOTE>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     if 
        ($tpl-&gt;Parsed(&quot;main.table.rows&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        $tpl-&gt;Parse(&quot;main.table.error&quot;);
     </font>
   </blockquote>
</blockquote>
<P></P>






<p>
<b><font size=+1>Printing templates / blocks:</font></b>
<br><br>
<font face="courier" color="#000000" size=+1>
function quickText($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
   <b>quickText</b> 
        returns the content of a value associated with a specified block by <i>$part</i>. You can refer directly to a sub-block or 
        to the main block of the template. The function is usually used after 
        the block is parsed at least once. If the value is empty the result is 
        not affected by the value set with <i>DefaultBlockValue</i> function.
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)
   </blockquote>
</blockquote>
 <b>Returns:</b>
   <blockquote>
     The function returns the current content of 
    the value associated with the block.
   </blockquote>
<BLOCKQUOTE></BLOCKQUOTE>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
     echo $tpl-&gt;quickText(&quot;main.table.rows&quot;);<br>                      
     echo $tpl-&gt;quickText(&quot;main&quot;);<br>
     </font>
   </blockquote>
</blockquote>
<P></P>



<p>
<br><br>
<font face="courier" color="#000000" size=+1>
function 
quickPrint($part) 
</font>
<br>

<blockquote>
 <b>Description:</b>
   <blockquote>
    <b>quickPrint</b> 
        print the result of quickText of a specified block. See <i>quickText</i>.
   </blockquote>
</blockquote>
<blockquote>
 <b>Parameters:</b>
   <blockquote>
     <b>$part</b> (<i>string</i>)<br>
     $part is a 
        refference to a block (See <b>Block Refference</b> 
        for more info.)
   </blockquote>
</blockquote>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
      $tpl-&gt;quickPrint(&quot;main.table.rows&quot;);<br>                      
      $tpl-&gt;quickPrint(&quot;main&quot;);<br>
     </font>
   </blockquote>
</blockquote>
<P></P>





<p>
<b><font size=+1>Variables:</font></b>
<br><br>

<blockquote>
The <i>variables</i> of 
    a template must be between brackets (<b>ex.:</b>&quot;{TITLE}&quot;). Allowed chars for the name of a variable 
    are:
<b>a-z, A-Z, 0-9, _</b>.<br>But 
    there are some new rules for this class. If the variable is associated with 
    a <b>simple value</b> (<i>string, 
    number</i>) the variable appears in the template between breackets:
<blockquote>{TITLE_OF_THE_PAGE}</blockquote>There are no 
    limits of the lenght of a variable name.<br>
<br>
If with a variable is associated an <b>array</b> then the variable cannot appear in the template. But here are 
    the best point: you can refer directly the key of the array in the template. 
    So, we made the next assign :
<blockquote>
 $data = array(&quot;NAME&quot; =&gt; 
        &quot;John Smith&quot;, &quot;AGE&quot; =&gt; 23, &quot;ADDRESS&quot; 
        =&gt; &quot;Romania ...&quot;);<br>
 $tpl-&gt;Assign(&quot;MYDATA&quot;, $data);<br>
 <br>
 You can use now in the template this 
        variables:<br>
 {MYDATA.NAME}<br>
 {MYDATA.AGE}<br>
 {MYDATA.ADDRESS}<br>
 
</blockquote>
</blockquote>

<blockquote>
You can insert a other file by using the 
    following tag: {HTML_SOURCE: <EM>url</EM>} where the url could be a local 
    file (relative or absolute path) or a url like &quot; http://www.bebe.home.ro/&quot; etc...<br>
	<b>NOTE:</b> Any file included are not parsed by QuickTemplate!
</blockquote>

<blockquote>
There are some default values. This values 
    are prefixed by &quot;DEFAULTS&quot;. For now are available the following 
    values:
 <li>{DEFAULTS.DATE}
 <li>{DEFAULTS.TIME}
 <li>{DEFAULTS.SELFURL}
 <li>{DEFAULTS.AUTOINCREMENT} (see <b>Auto-increment</b>)
 <li>{DEFAULTS.VERSION} // Version of class
 <br>
<i>(I'm wainting for any other 
    suggestions ...)</i></li>
</blockquote>
<P></P>


<p>
<b><font size=+1>Block Reference:</font></b>
<br><br>

<blockquote>
Any block can be refered directly. Let's say 
    that a block named <b>&quot;row&quot;</b> is a child of 
    a block <b>&quot;table&quot;</b> and this block is a 
    child of the block named <b>&quot;main&quot;</b>. We can 
    refer now the row block by the following string 
<b>&quot;main.table.row&quot;</b>. If the reference string is not 
    correctly formated the function that processes the refernce will verify the 
    structure and will return an error.
<br>
<blockquote>
 <b>Examples:</b>
   <blockquote>
     <font face="arial">     
      $tpl-&gt;SetAutoincrement(&quot;main.table.rows&quot;, 
            1,10);<br>
      $tpl-&gt;parse(&quot;main.table.rows&quot;);<br>
      $tpl-&gt;quickPrint(&quot;main.table.rows&quot;);<br>                      
     </font>
   </blockquote>
</blockquote>
</blockquote>
<P></P>

<hr>

<p>
<b><font size=+1>Short Example:</font></b>
<br><br>

<blockquote>
<b>The Template :</b><i>(file name: first_example.tpl)</i>
 <blockquote>
 <pre>&lt;!-- BEGIN BLOCK: main --&gt;

{HTML_SOURCE: some/local/directory/header.html}

    {HTML_SOURCE: http://server/some/remote/directory/page.html}

&lt;h1&gt;This is a test of {DEFAULTS.VERSION}.Author: {MYNAME}&lt;/h1&gt;
The location of this file is: {DEFAULTS.SELFURL}&lt;br&gt;
&lt;hr&gt;

 &lt;!-- BEGIN BLOCK: table --&gt;
 &lt;table border=&quot;1&quot;&gt;
 &lt;tr&gt;
  &lt;td&gt;Crt.no.&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;
  &lt;td&gt;Mark&lt;/td&gt;&lt;td&gt;Class room&lt;/td&gt;
 &lt;/tr&gt;

  &lt;!-- BEGIN BLOCK: row --&gt;
    &lt;tr&gt;
     &lt;td&gt;{DEFAULTS.AUTOINCREMENT}&lt;/td&gt;
     &lt;td&gt;{DATA.NAME}&lt;/td&gt;
     &lt;td align=&quot;right&quot;&gt;{DATA.MARK}&lt;/td&gt;
     &lt;td&gt;{CLASSROOM}&lt;/td&gt;
    &lt;/tr&gt;
  &lt;!-- END BLOCK: row --&gt;
  &lt;!-- BEGIN BLOCK: error --&gt;
   &lt;tr&gt;&lt;td colspan=&quot;4&quot;&gt;&lt;font color=&quot;red&quot;&gt;
   No students in class {CLASSROOM}
   &lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;!-- END BLOCK: error --&gt;

 &lt;/table&gt;
 &lt;!-- END BLOCK: table --&gt;

&lt;p align=&quot;right&quot;&gt;
Current time &lt;b&gt;{DEFAULTS.TIME}&lt;/b&gt;&lt;br&gt;
Date: &lt;b&gt;{DEFAULTS.DATE}&lt;/b&gt;&lt;br&gt;
&lt;p&gt;
{HTML_SOURCE: some/local/directory/footer.html}
&lt;!-- END BLOCK: main --&gt;
 </pre>
 </blockquote>
<b>The source file :</b>   
 <blockquote>
<pre>&lt;?
require (&quot;class.QuickTemplate.php3&quot;);

$tpl = new QuickTemplate(&quot;first_example.tpl&quot;);

$MARKS[&quot;John&quot;] = 10;
$MARKS[&quot;Michael&quot;] = 9;
$MARKS[&quot;Bob&quot;] = 7;
$MARKS[&quot;Robert&quot;] = 8;
$MARKS[&quot;Jane&quot;] = 7;
$MARKS[&quot;Alice&quot;] = 9;
$MARKS[&quot;David&quot;] = 10;
$MARKS[&quot;James&quot;] = 8;
$MARKS[&quot;Toni&quot;] = 7;
$MARKS[&quot;Bebe&quot;] = 9;

$CLASSES[&quot;101A&quot;] = array(&quot;John&quot;, &quot;Robert&quot;, &quot;Jane&quot;);
$CLASSES[&quot;101B&quot;] = array(&quot;Bob&quot;, &quot;Alice&quot;, &quot;Bebe&quot;, &quot;Toni&quot;);
$CLASSES[&quot;100C&quot;] = array(&quot;Michael&quot;, &quot;David&quot;, &quot;James&quot;);
$CLASSES[&quot;100D&quot;] = array();

$tpl-&gt;SetNullString(&quot; &lt;b&gt;-&lt;/b&gt;&quot;);
$tpl-&gt;SetAutoincrement(&quot;main.table.row&quot;, 1);
$tpl-&gt;Assign(&quot;MYNAME&quot;, &quot;Stefan Bocskai&quot;);

while (list($Class, $Members) = each($CLASSES))
 {
  $tpl-&gt;Assign(&quot;CLASSROOM&quot;,$Class);
   if (gettype($Members) == &quot;array&quot;)
    while (list($k, $member) = each($Members))
   {
    $MEMBERDATA = array(NAME =&gt; $member,
                        MARK =&gt; $MARKS[$member]);

    $tpl-&gt;AssignLocal(&quot;main.table.row&quot;, &quot;DATA&quot;, $MEMBERDATA);

    $tpl-&gt;parse(&quot;main.table.row&quot;);
   }

   if (!$tpl-&gt;Parsed(&quot;main.table.row&quot;))
            $tpl-&gt;parse(&quot;main.table.error&quot;);

   $tpl-&gt;parse(&quot;main.table&quot;);
 }

$tpl-&gt;parse(&quot;main&quot;);

$tpl-&gt;quickPrint(&quot;main&quot;);

?&gt;
</pre>

 </blockquote>
</blockquote>
<P></P>

<blockquote>
<b>Results: </b>
 <blockquote>




<h1>This is a test of QuickTemplate V2.3. Author: Stefan Bocskai
    </h1>The location of this file is: 
        /group/testes/teste_bebe1.phtml<br>
<hr> 

 
 <table border="1">
 <tr>
  <td>Crt.no.</td><td>Name</td><td>Mark</td><td>Class room</td>
 </tr>

  
    <tr>
     <td>1</td>
     <td>John</td>
     <td align="right">10</td>
     <td>101A</td>
    </tr>
  
    <tr>
     <td>2</td>
     <td>Robert</td>
     <td align="right">8</td>
     <td>101A</td>
    </tr>
  
    <tr>
     <td>3</td>
     <td>Jane</td>
     <td align="right">7</td>
     <td>101A</td>
    </tr>&nbsp; 

 </table>
 
 <table border="1">
 <tr>
  <td>Crt.no.</td><td>Name</td><td>Mark</td><td>Class room</td>
 </tr>

  
    <tr>
     <td>1</td>
     <td>Bob</td>
     <td align="right">7</td>
     <td>101B</td>
    </tr>
  
    <tr>
     <td>2</td>
     <td>Alice</td>
     <td align="right">9</td>
     <td>101B</td>
    </tr>
  
    <tr>
     <td>3</td>
     <td>Bebe</td>
     <td align="right">9</td>
     <td>101B</td>
    </tr>
  
    <tr>
     <td>4</td>
     <td>Toni</td>
     <td align="right">7</td>
     <td>101B</td>
    </tr>&nbsp; 

 </table>
 
 <table border="1">
 <tr>
  <td>Crt.no.</td><td>Name</td><td>Mark</td><td>Class room</td>
 </tr>

  
    <tr>
     <td>1</td>
     <td>Michael</td>
     <td align="right">9</td>
     <td>100C</td>
    </tr>
  
    <tr>
     <td>2</td>
     <td>David</td>
     <td align="right">10</td>
     <td>100C</td>
    </tr>
  
    <tr>
     <td>3</td>
     <td>James</td>
     <td align="right">8</td>
     <td>100C</td>
    </tr>&nbsp; 

 </table>
 
 <table border="1">
 <tr>
  <td>Crt.no.</td><td>Name</td><td>Mark</td><td>Class room</td>
 </tr>&nbsp;
  
   <tr><td colspan="4"><font color="red">No students in class 100D 
 
   </font></td></tr>
   

 </table>
 

<p align="right">
Current time <b>13:41 PM</b><br>
Date: <b>Tuesday 09 May 2000</b><br>
<p></p>




 </blockquote>
</blockquote>
</body>
</html>