|
{block} <p> It's possible to put a PHP file in the directory '_callbacks' that is called back at the processing of a pad tag.<br> - With option 'before' the callback happens for every occurrence before the processing of the ocurrences.<br> - With option 'demand' the callback happens during the processing of the occurrences.
</p> {/block}
{example 'callback/before', php='_callbacks/before.php', skipClose} {example 'callback/demand', php='_callbacks/demand.php', skipOpen}
|
|
It's possible to put a PHP file in the directory '_callbacks' that is called back at the processing of a pad tag.
- With option 'before' the callback happens for every occurrence before the processing of the ocurrences.
- With option 'demand' the callback happens during the processing of the occurrences.
|
PHP _callbacks/before.php
|
HTML callback/before.pad
|
Result
|
<?php
switch ($padCallback) {
case 'init':
$salaryTotal = 0; $bonusTotal = 0;
break;
case 'row':
$row ['total'] = $row ['salary'] + $row ['bonus'];
$salaryTotal += $row ['salary']; $bonusTotal += $row ['bonus'];
break;
case 'exit':
$totalTotal = $salaryTotal + $bonusTotal ;
break;
}
?> |
<table border=1>
<tr> <th>Name</th> <th>Salary</th> <th>Bonus</th> <th>Total</th> </tr> {staff callback='before.php', before}
{first} <tr> <td>Totals</td> <td>{$salaryTotal | %.2f}</td> <td>{$bonusTotal | %.2f}</td> <td>{$totalTotal | %.2f}</td> </tr> {/first}
<tr align="right" bgcolor="{switch 'yellow', 'pink'}"> <td align="left">{$name | capitalize}</td> <td>{$salary | %.2f}</td> <td>{$bonus | %.2f}</td> <td>{$total | %.2f}</td> </tr>
{/staff} </table>
|
| Name |
Salary |
Bonus |
Total |
| Totals |
15000.00 |
1500.00 |
16500.00 |
| Joe |
1000.00 |
500.00 |
1500.00 |
| Jim |
2000.00 |
400.00 |
2400.00 |
| John |
3000.00 |
300.00 |
3300.00 |
| Jack |
4000.00 |
200.00 |
4200.00 |
| Jerry |
5000.00 |
100.00 |
5100.00 |
|
PHP _callbacks/demand.php
|
HTML callback/demand.pad
|
Result
|
<?php
switch ($padCallback) {
case 'init':
$salaryTotal = 0; $bonusTotal = 0;
break;
case 'row':
$total = $salary + $bonus;
$salaryTotal += $salary; $bonusTotal += $bonus;
break;
case 'exit':
$totalTotal = $salaryTotal + $bonusTotal ;
break;
}
?> |
<table border=1>
<tr> <th>Name</th> <th>Salary</th> <th>Bonus</th> <th>Total</th> </tr> {staff callback='demand.php', demand}
<tr align="right" bgcolor="{switch 'yellow', 'pink'}"> <td align="left">{$name | capitalize}</td> <td>{$salary | %.2f}</td> <td>{$bonus | %.2f}</td> <td>{$total | %.2f}</td> </tr>
{/staff}
<tr> <td>Totals</td> <td>{$salaryTotal | %.2f}</td> <td>{$bonusTotal | %.2f}</td> <td>{$totalTotal | %.2f}</td> </tr> </table>
|
| Name |
Salary |
Bonus |
Total |
| Joe |
1000.00 |
500.00 |
1500.00 |
| Jim |
2000.00 |
400.00 |
2400.00 |
| John |
3000.00 |
300.00 |
3300.00 |
| Jack |
4000.00 |
200.00 |
4200.00 |
| Jerry |
5000.00 |
100.00 |
5100.00 |
| Totals |
15000.00 |
1500.00 |
16500.00 |
|
|