-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexamples.php
99 lines (79 loc) · 2.15 KB
/
examples.php
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
<?php
/**
* ---------------------------------------------------------------------------
* Stamp t.e. Examples
* @author Gabor de Mooij
* ---------------------------------------------------------------------------
*/
require( 'StampTE.php' );
use StampTemplateEngine\StampTE as StampTE;
use StampTemplateEngine\StampTEException as StampTEException;
/**
* ---------------------------------------------------------------------------
* Example #1: Pizza prices, an introduction
* ---------------------------------------------------------------------------
*/
$t = '
<table>
<thead><tr><th>Pizza</th><th>Price</th></tr></thead>
<tbody>
<!-- cut:pizza -->
<tr><td>#name#</td><td>#price#</td></tr>
<!-- /cut:pizza -->
</tbody>
</table>
';
$data = array(
'Magaritha' => '6.99',
'Funghi' => '7.50',
'Tonno' => '7.99'
);
$priceList = new StampTE( $t );
$dish = $priceList->getPizza();
foreach( $data as $name => $price ) {
$pizza = $dish->copy();
$pizza
->setName( $name )
->setPrice( $price );
$priceList->add( $pizza );
}
echo $priceList;
/**
* ---------------------------------------------------------------------------
* Example #2: Building a form, the basics
* ---------------------------------------------------------------------------
*/
$t = '
<form action="#action#" method="post">
<!-- cut:textField -->
<label>#label#</label><input type="text" name="#name#" value="#value#" />
<!-- /cut:textField -->
</form>
';
$form = new StampTE( $t );
$textField = $form->getTextField();
$textField
->setLabel( 'Your Name' )
->setName( 'person' )
->setValue( 'It\'s me!' );
$form->add( $textField );
echo "\n\n\n".$form;
/**
* ---------------------------------------------------------------------------
* Example #3: Game, multiple templates
* ---------------------------------------------------------------------------
*/
$vt = '<div id="forest"><div id="village"><!-- paste:village --></div></div>';
$bt = '
<div class="catalogue">
<!-- cut:tavern -->
<img src="tavern.gif" />
<!-- /cut:tavern -->
</div>
';
$v = new StampTE( $vt );
$b = new StampTE( $bt );
$tavern = $b->getTavern();
$v->village->add( $tavern );
echo "\n\n\n".$v;
exit;