54 $this->
openTag($compiler,
'section', array(
'section', $compiler->nocache));
56 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
60 $section_name = $_attr[
'name'];
62 $output .=
"if (isset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name])) unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n";
63 $section_props =
"\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]";
65 foreach ($_attr as $attr_name => $attr_value) {
68 $output .=
"{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int)\$_loop); unset(\$_loop);\n";
72 if (is_bool($attr_value))
73 $show_attr_value = $attr_value ?
'true' :
'false';
75 $show_attr_value =
"(bool)$attr_value";
76 $output .=
"{$section_props}['show'] = $show_attr_value;\n";
80 $output .=
"{$section_props}['$attr_name'] = $attr_value;\n";
85 $output .=
"{$section_props}['$attr_name'] = (int)$attr_value;\n";
89 $output .=
"{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n";
94 if (!isset($_attr[
'show']))
95 $output .=
"{$section_props}['show'] = true;\n";
97 if (!isset($_attr[
'loop']))
98 $output .=
"{$section_props}['loop'] = 1;\n";
100 if (!isset($_attr[
'max']))
101 $output .=
"{$section_props}['max'] = {$section_props}['loop'];\n";
103 $output .=
"if ({$section_props}['max'] < 0)\n" .
" {$section_props}['max'] = {$section_props}['loop'];\n";
105 if (!isset($_attr[
'step']))
106 $output .=
"{$section_props}['step'] = 1;\n";
108 if (!isset($_attr[
'start']))
109 $output .=
"{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
111 $output .=
"if ({$section_props}['start'] < 0)\n" .
" {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
"else\n" .
" {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
114 $output .=
"if ({$section_props}['show']) {\n";
115 if (!isset($_attr[
'start']) && !isset($_attr[
'step']) && !isset($_attr[
'max'])) {
116 $output .=
" {$section_props}['total'] = {$section_props}['loop'];\n";
118 $output .=
" {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
120 $output .=
" if ({$section_props}['total'] == 0)\n" .
" {$section_props}['show'] = false;\n" .
"} else\n" .
" {$section_props}['total'] = 0;\n";
122 $output .=
"if ({$section_props}['show']):\n";
124 for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1;
125 {$section_props}['iteration'] <= {$section_props}['total'];
126 {$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
127 $output .=
"{$section_props}['rownum'] = {$section_props}['iteration'];\n";
128 $output .=
"{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n";
129 $output .=
"{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n";
130 $output .=
"{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n";
131 $output .=
"{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n";
159 list($openTag, $nocache) = $this->
closeTag($compiler, array(
'section'));
160 $this->
openTag($compiler,
'sectionelse', array(
'sectionelse', $nocache));
162 return "<?php endfor; else: ?>";
188 if ($compiler->nocache) {
189 $compiler->tag_nocache =
true;
192 list($openTag, $compiler->nocache) = $this->
closeTag($compiler, array(
'section',
'sectionelse'));
194 if ($openTag ==
'sectionelse') {
195 return "<?php endif; ?>";
197 return "<?php endfor; endif; ?>";
compile($args, $compiler)
Compiles code for the {section} tag.
openTag($compiler, $openTag, $data=null)
Push opening tag name on stack.
compile($args, $compiler)
Compiles code for the {sectionelse} tag.
getAttributes($compiler, $attributes)
This function checks if the attributes passed are valid.
compile($args, $compiler)
Compiles code for the {/section} tag.
closeTag($compiler, $expectedTag)
Pop closing tag.