#native_company# #native_desc#
#native_cta#

PHP Templates: Revisited Page 4

By Polerio Babao
on September 9, 2002

First, DynamicRows, why such a name? Because rows are not fixed, it’s dynamic. $Prefix, this is used to determine or distinguish this loopings from other dynamic data you would want to create. Perhaps you want to lists some author/name into another table, with this you have the ability to distinguish it from the other. From the HTML given we use here a prefix “9a”. We can see that “9a” appears on a dynamic table that will loop dependent upon the size of the array with which you store some value. Take note that we again use an array here to store values so that we could pass this values from one function to another.
$LoadTemplate, we use again load template function here because we are going to parse its dynamic variables. We have $RowName, this is the dynamic variables which will have some values after the parsing has been done, this is dynamic in a sense that this $RowName is unlimited. In our example these are the , , variables which will have some values after the parsing. The values which will be encoded in here will again come from an array. You can set as many column as you want because this function is flexible. You can add another field perhaps a rank, which increments when someone reads an article. We have a $RowValue variable, this is where the values will be passed. To get more idea of this concept do analyse line by line the coding of this function. But explaining it briefly, this function simply parses the template starting from reading/finding the BEGIN_MESSAGE_LIST comment up to END_MESSAGE_LIST comment, after this the function will loop through that variables dependent upon the size of the array which was taken from count(somearray) function. While looping through the MESSAGE_LIST comment, it is replacing one by one the values into the template variables thus giving a dynamic values.

<?php

<!--%00_BEGIN_NO_MESSAGES%-->

    <!--%
97_BEGIN_NO_MESSAGES%-->

    <
table border="1">

    <
tr>Date</td><td>Title</td><td>Author</td></tr>

    <!--%
9a_BEGIN_MESSAGE_LIST%-->

    <!--%
9a_ML_LOOPBEGIN%-->

    <
tr><td><!--%9adate_____%--></td><td><!--%9atitle____%--></td><td><!--%9aauthor___%--></td></tr>

    <!--%
9a_ML_LOOPEND%-->

    </
table>

    <!--%
9a_END_MESSAGE_LIST%-->

    <!--%
97_END_NO_MESSAGES%-->

<!--%
00_END_NO_MESSAGES%-->

?>



Applying this concept, the following code should be added to put values into the variables of your template.

<?php

$result
[0] = array("09/28/02","Parsing made simple","Juan Tamad");

$result[1] = array("09/30/02","PHP template revisited","Polerio Babao");

$tcontent $LoadTemplate;

$Prefix "9a"$RowValue $result;

$RowName = array("<!--%9adate_____%-->","<!--%9atitle____%-->","<!--%9aauthor___%-->");

echo 
$tcontent DynamicRows($Prefix$tcontent$RowName$RowValue);

?>



Now we have again a call for loading the template so that the parser will be able to determine the variables in template.html file. The prefix variable has been defined clearly. The result can be taken into your mysql result or any database application.

1
|
2
|
3
|
4
|
5
|
6
|
7