1 |
1559
|
Luisehahne
|
QuickSkin Control Structures (Used within templates)
|
2 |
|
|
|
3 |
|
|
Control Structure - IF
|
4 |
|
|
|
5 |
|
|
The if ... endif construct facilitates the conditional presentation of template fragments.
|
6 |
|
|
|
7 |
|
|
The syntax can be one of the following:
|
8 |
|
|
|
9 |
|
|
<!-- IF var --> var is not empty! <!-- ENDIF var -->
|
10 |
|
|
<!-- IF name=='John Doe' --> Your name is John Doe! <!-- ENDIF name -->
|
11 |
|
|
<!-- IF name!='John Doe' --> Your name is not John Doe! <!-- ENDIF name -->
|
12 |
|
|
|
13 |
|
|
A variable can be used as right part of the IF clause using the folloging syntax:
|
14 |
|
|
|
15 |
|
|
<!-- IF name=variablename --> Your name match with {variablename} <!-- ENDIF name -->
|
16 |
|
|
<!-- IF name!=top.variablename --> Your name doesn't match with {top.variablename} <!-- ENDIF name -->
|
17 |
|
|
|
18 |
|
|
* (var after ENDIF is optional)
|
19 |
|
|
* the 'var' comes from your PHP code
|
20 |
|
|
* IF/ELSE/ELSEIF control structures can be nested in other IF or LOOP control structures
|
21 |
|
|
|
22 |
|
|
Control Structure - ELSE
|
23 |
|
|
|
24 |
|
|
The else construct extends an if construct to display a template fragment in case the
|
25 |
|
|
expression in the if statement evaluates to FALSE.
|
26 |
|
|
|
27 |
|
|
<!-- IF usergroup="ADMIN" -->
|
28 |
|
|
<a href="admin.php"> ADMIN Login </a><br />
|
29 |
|
|
<!-- ELSE -->
|
30 |
|
|
You are in guest mode!<br />
|
31 |
|
|
<!-- ENDIF usergroup -->
|
32 |
|
|
|
33 |
|
|
* (var after ENDIF is optional)
|
34 |
|
|
* the 'var' comes from your PHP code
|
35 |
|
|
* IF/ELSE/ELSEIF control structures can be nested in other IF or LOOP control structures
|
36 |
|
|
|
37 |
|
|
Control Structure - ELSEIF
|
38 |
|
|
|
39 |
|
|
The elseif construct is a combination of an else and if construct.
|
40 |
|
|
|
41 |
|
|
<!-- IF usergroup="ADMIN" -->
|
42 |
|
|
<a href="admin.php"> Admin Staff Login </a><br />
|
43 |
|
|
<!-- ELSEIF usergroup="SUPPORT" -->
|
44 |
|
|
<a href="support.php"> Support Staff Login </a><br />
|
45 |
|
|
<!-- ELSEIF usergroup -->
|
46 |
|
|
<a href="other.php"> Standard Login </a><br />
|
47 |
|
|
<!-- ELSE -->
|
48 |
|
|
You don't even have a usergroup!
|
49 |
|
|
<!-- ENDIF -->
|
50 |
|
|
|
51 |
|
|
* (var after ENDIF is optional)
|
52 |
|
|
* the 'var' comes from your PHP code
|
53 |
|
|
* IF/ELSE/ELSEIF control structures can be nested in other IF or LOOP control structures
|
54 |
|
|
|
55 |
|
|
Control Structure - LOOP ... ENDLOOP
|
56 |
|
|
|
57 |
|
|
The loop ... endloop construct facilitates a way to iterate through numeric arrays.
|
58 |
|
|
Each element of the numeric array is expected to be an associative array and is used
|
59 |
|
|
to parse the template fragment that is embedded between the
|
60 |
|
|
<!-- LOOP --> and <!-- ENDLOOP -->
|
61 |
|
|
tags like it was a small template itself.
|
62 |
|
|
|
63 |
|
|
Each associative array is expanded by the following two additional elements:
|
64 |
|
|
|
65 |
|
|
ROWCNT : The actual position of this element within the parent array. (0,1,2,3,...n)
|
66 |
|
|
ROWBIT : The least significant bit of ROWCNT. (0,1,0,1,0,1,...)
|
67 |
|
|
|
68 |
|
|
loop ... endloop blocks can easily be nested and parsed recursivly.
|
69 |
|
|
|
70 |
|
|
Example, assuming this code precedes in your PHP:
|
71 |
|
|
|
72 |
|
|
$users = array(
|
73 |
|
|
array( 'NAME' => 'John Doe', 'GROUP' => 'ADMIN' ),
|
74 |
|
|
array( 'NAME' => 'Jack Doe', 'GROUP' => 'SUPPORT' ),
|
75 |
|
|
array( 'NAME' => 'James Doe', 'GROUP' => 'GUEST' ),
|
76 |
|
|
array( 'NAME' => 'Jane Doe', 'GROUP' => 'GUEST' ),
|
77 |
|
|
);
|
78 |
|
|
$page->assign( 'users', $users );
|
79 |
|
|
|
80 |
|
|
The template, then, would contain:
|
81 |
|
|
|
82 |
|
|
<style type="text/css">
|
83 |
|
|
.col0 { background-color: #D0D0D0; }
|
84 |
|
|
.col1 { background-color: #F0F0F0; }
|
85 |
|
|
</style>
|
86 |
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
87 |
|
|
<tr>
|
88 |
|
|
<th>No.</th>
|
89 |
|
|
<th>Username</th>
|
90 |
|
|
<th>Usergroup</th>
|
91 |
|
|
</tr>
|
92 |
|
|
<!-- LOOP users -->
|
93 |
|
|
<tr class="col{ROWBIT}">
|
94 |
|
|
<td>{ROWCNT}</td>
|
95 |
|
|
<td>{NAME}</td>
|
96 |
|
|
<td>{GROUP}</td>
|
97 |
|
|
</tr>
|
98 |
|
|
<!-- ENDLOOP users -->
|
99 |
|
|
</table>
|
100 |
|
|
|
101 |
|
|
* (var after ENDLOOP is optional)
|
102 |
|
|
* the 'var' comes from your PHP code
|
103 |
|
|
* IF/ELSE/ELSEIF control structures can be nested in other IF or LOOP control structures
|
104 |
|
|
* LOOP/ENDLOOP control structures can be nested in other IF or LOOP control structures
|
105 |
|
|
|
106 |
|
|
Control Structure - INCLUDE
|
107 |
|
|
|
108 |
|
|
While not a true Control Structure, the INCLUDE directive loads external data, in place, in your template.
|
109 |
|
|
|
110 |
|
|
Templates can be included in other templates by using the INCLUDE statement.
|
111 |
|
|
All functionality available to the main template is also available to the sub template
|
112 |
|
|
(variable substitution, etc.). This permit the use of subtemplating.
|
113 |
|
|
|
114 |
|
|
The syntax is:
|
115 |
|
|
|
116 |
|
|
<!-- INCLUDE templatename.html -->
|
117 |
|
|
|
118 |
|
|
* file to include is in the template directory (default '_skins/')
|
119 |
|
|
* similar to the method $page->addtpl() ... difference is that 'addtpl' stores the data
|
120 |
|
|
in a variable that then gets assigned ('$page->assign()') within the main template
|
121 |
|
|
|