mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
Made 'name' attribute optional for {foreach}.
This commit is contained in:
@@ -557,17 +557,16 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_syntax_error("missing 'item' attribute");
|
$this->_syntax_error("missing 'item' attribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($attrs['name'])) {
|
|
||||||
$this->_syntax_error("missing 'name' attribute");
|
|
||||||
}
|
|
||||||
|
|
||||||
$from = $attrs['from'];
|
$from = $attrs['from'];
|
||||||
$item = $this->_dequote($attrs['item']);
|
$item = $this->_dequote($attrs['item']);
|
||||||
$name = $attrs['name'];
|
if (isset($attrs['name']))
|
||||||
|
$name = $attrs['name'];
|
||||||
|
|
||||||
$output = '<?php ';
|
$output = '<?php ';
|
||||||
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
if (isset($name)) {
|
||||||
$foreach_props = "\$this->_foreach[$name]";
|
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
||||||
|
$foreach_props = "\$this->_foreach[$name]";
|
||||||
|
}
|
||||||
|
|
||||||
$key_part = '';
|
$key_part = '';
|
||||||
|
|
||||||
@@ -584,14 +583,19 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
if (isset($name)) {
|
||||||
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
||||||
$output .= "if ({$foreach_props}['show']):\n";
|
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
||||||
$output .= "{$foreach_props}['iteration'] = 0;\n";
|
$output .= "if ({$foreach_props}['show']):\n";
|
||||||
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
$output .= "{$foreach_props}['iteration'] = 0;\n";
|
||||||
$output .= " {$foreach_props}['iteration']++;\n";
|
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
$output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n";
|
$output .= " {$foreach_props}['iteration']++;\n";
|
||||||
$output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n";
|
$output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n";
|
||||||
|
$output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n";
|
||||||
|
} else {
|
||||||
|
$output .= "if (count((array)$from)):\n";
|
||||||
|
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
|
}
|
||||||
$output .= '?>';
|
$output .= '?>';
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
@@ -557,17 +557,16 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$this->_syntax_error("missing 'item' attribute");
|
$this->_syntax_error("missing 'item' attribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($attrs['name'])) {
|
|
||||||
$this->_syntax_error("missing 'name' attribute");
|
|
||||||
}
|
|
||||||
|
|
||||||
$from = $attrs['from'];
|
$from = $attrs['from'];
|
||||||
$item = $this->_dequote($attrs['item']);
|
$item = $this->_dequote($attrs['item']);
|
||||||
$name = $attrs['name'];
|
if (isset($attrs['name']))
|
||||||
|
$name = $attrs['name'];
|
||||||
|
|
||||||
$output = '<?php ';
|
$output = '<?php ';
|
||||||
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
if (isset($name)) {
|
||||||
$foreach_props = "\$this->_foreach[$name]";
|
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
||||||
|
$foreach_props = "\$this->_foreach[$name]";
|
||||||
|
}
|
||||||
|
|
||||||
$key_part = '';
|
$key_part = '';
|
||||||
|
|
||||||
@@ -584,14 +583,19 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
if (isset($name)) {
|
||||||
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
||||||
$output .= "if ({$foreach_props}['show']):\n";
|
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
||||||
$output .= "{$foreach_props}['iteration'] = 0;\n";
|
$output .= "if ({$foreach_props}['show']):\n";
|
||||||
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
$output .= "{$foreach_props}['iteration'] = 0;\n";
|
||||||
$output .= " {$foreach_props}['iteration']++;\n";
|
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
$output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n";
|
$output .= " {$foreach_props}['iteration']++;\n";
|
||||||
$output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n";
|
$output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n";
|
||||||
|
$output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n";
|
||||||
|
} else {
|
||||||
|
$output .= "if (count((array)$from)):\n";
|
||||||
|
$output .= " foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
|
}
|
||||||
$output .= '?>';
|
$output .= '?>';
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
Reference in New Issue
Block a user