39 public function compile($args, $compiler, $parameter)
41 if ($parameter == 0) {
42 $this->required_attributes = array(
'start',
'to');
43 $this->optional_attributes = array(
'max',
'step');
45 $this->required_attributes = array(
'start',
'ifexp',
'var',
'step');
46 $this->optional_attributes = array();
52 if ($parameter == 1) {
53 foreach ($_attr[
'start'] as $_statement) {
54 $output .=
" \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
55 $output .=
" \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n";
57 $output .=
" if ($_attr[ifexp]){ for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[step]){\n";
59 $_statement = $_attr[
'start'];
60 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
61 if (isset($_attr[
'step'])) {
62 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
64 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
66 if (isset($_attr[
'max'])) {
67 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)min(ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step)),$_attr[max]);\n";
69 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int)ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step));\n";
71 $output .=
"if (\$_smarty_tpl->tpl_vars[$_statement[var]]->total > 0){\n";
72 $output .=
"for (\$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value], \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration = 1;\$_smarty_tpl->tpl_vars[$_statement[var]]->iteration <= \$_smarty_tpl->tpl_vars[$_statement[var]]->total;\$_smarty_tpl->tpl_vars[$_statement[var]]->value += \$_smarty_tpl->tpl_vars[$_statement[var]]->step, \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration++){\n";
73 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->first = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == 1;";
74 $output .=
"\$_smarty_tpl->tpl_vars[$_statement[var]]->last = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == \$_smarty_tpl->tpl_vars[$_statement[var]]->total;";
78 $this->
openTag($compiler,
'for', array(
'for', $compiler->nocache));
80 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
103 public function compile($args, $compiler, $parameter)
108 list($openTag, $nocache) = $this->
closeTag($compiler, array(
'for'));
109 $this->
openTag($compiler,
'forelse', array(
'forelse', $nocache));
110 return "<?php }} else { ?>";
131 public function compile($args, $compiler, $parameter)
136 if ($compiler->nocache) {
137 $compiler->tag_nocache =
true;
140 list($openTag, $compiler->nocache) = $this->
closeTag($compiler, array(
'for',
'forelse'));
142 if ($openTag ==
'forelse') {
145 return "<?php }} ?>";
compile($args, $compiler, $parameter)
Compiles code for the {/for} tag.
compile($args, $compiler, $parameter)
Compiles code for the {for} tag.
openTag($compiler, $openTag, $data=null)
Push opening tag name on stack.
getAttributes($compiler, $attributes)
This function checks if the attributes passed are valid.
closeTag($compiler, $expectedTag)
Pop closing tag.
compile($args, $compiler, $parameter)
Compiles code for the {forelse} tag.