Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | /** |
||
3 | * Smarty Internal Plugin Compile For |
||
4 | * |
||
5 | * Compiles the {for} tag |
||
6 | * |
||
7 | * @package Smarty |
||
8 | * @subpackage Compiler |
||
9 | * @author Uwe Tews |
||
10 | */ |
||
11 | /** |
||
12 | * Smarty Internal Plugin Compile For Class |
||
13 | */ |
||
14 | class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase { |
||
15 | /** |
||
16 | * Compiles code for the {for} tag |
||
17 | * |
||
18 | * Smarty 3 does implement two different sytaxes: |
||
19 | * |
||
20 | * - {for $var in $array} |
||
21 | * For looping over arrays or iterators |
||
22 | * |
||
23 | * - {for $x=0; $x<$y; $x++} |
||
24 | * For general loops |
||
25 | * |
||
26 | * The parser is gereration different sets of attribute by which this compiler can |
||
27 | * determin which syntax is used. |
||
28 | * |
||
29 | * @param array $args array with attributes from parser |
||
30 | * @param object $compiler compiler object |
||
31 | * @return string compiled code |
||
32 | */ |
||
33 | public function compile($args, $compiler) |
||
34 | { |
||
35 | $this->compiler = $compiler; |
||
36 | // {for $x=0; $x<$y; $x++} syntax |
||
37 | $this->required_attributes = array('ifexp', 'start', 'loop', 'varloop'); |
||
38 | // check and get attributes |
||
39 | $_attr = $this->_get_attributes($args); |
||
40 | |||
41 | $this->_open_tag('for'); |
||
42 | |||
43 | $output = "<?php "; |
||
44 | foreach ($_attr['start'] as $_statement) { |
||
45 | $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;"; |
||
46 | $output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n"; |
||
47 | } |
||
48 | $output .= " if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[varloop]]->value$_attr[loop]){\n"; |
||
49 | $output .= "?>"; |
||
50 | // return compiled code |
||
51 | return $output; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | ?> |