| Example 2 | |
|---|---|
This shows the use of loops and setting several parameters at once..
Program File
# 1: <?php
HTML template file
# 0: <?
Let's leave out what is explained in the first example and start:
This time we define an array holding all the parameters we want to pass. The first item will be the title for the address book $params['HEADLINE'] = "Myaddress book";Next, we make an entry that is a multi dimensional array. The first level is numerical and goes from 1 to 3 ( or rather 0 to 2). This holds the second level array that consists of key-value pairs for "Name" and "Phone Number" $params['ENTRIES'] = array(
array("Name"=>"John",
"Phone"=>"28877112"),
array("Name"=>"Jill",
"Phone"=>"4785521"),
array("Name"=>"My dog",
"Phone"=>"04487 445512")
);
Now we pass all this to the parser:
$STP->setParams($params);And output like in the first example. In our template file example2.tmpl the parser will now find the tag <#HEADLINE#> and fill it with the item called "HEADLINE" from our parameter array. Now the parser comes across the <#FOR ENTRIES#>. It looks if there is an array called "ENTRIES" and will start looping through it. On every iteration it will replace the values <#Name#> and <#Phone#> with the respective values from our second level arrays. See the result Important: If the parser does not find a parameter that matches a given tag this tag will be stripped. |
| .GR - Domains for you |
No residence restrictions - anybody can register
Registration starting at € 16,33 / year
Web Hosting incl. .gr-Domain from € 8,90 / month
|