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");
|
||||
}
|
||||
|
||||
if (empty($attrs['name'])) {
|
||||
$this->_syntax_error("missing 'name' attribute");
|
||||
}
|
||||
|
||||
$from = $attrs['from'];
|
||||
$item = $this->_dequote($attrs['item']);
|
||||
if (isset($attrs['name']))
|
||||
$name = $attrs['name'];
|
||||
|
||||
$output = '<?php ';
|
||||
if (isset($name)) {
|
||||
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
||||
$foreach_props = "\$this->_foreach[$name]";
|
||||
}
|
||||
|
||||
$key_part = '';
|
||||
|
||||
@@ -584,6 +583,7 @@ class Smarty_Compiler extends Smarty {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($name)) {
|
||||
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
||||
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
||||
$output .= "if ({$foreach_props}['show']):\n";
|
||||
@@ -592,6 +592,10 @@ class Smarty_Compiler extends Smarty {
|
||||
$output .= " {$foreach_props}['iteration']++;\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 .= '?>';
|
||||
|
||||
return $output;
|
||||
|
@@ -557,17 +557,16 @@ class Smarty_Compiler extends Smarty {
|
||||
$this->_syntax_error("missing 'item' attribute");
|
||||
}
|
||||
|
||||
if (empty($attrs['name'])) {
|
||||
$this->_syntax_error("missing 'name' attribute");
|
||||
}
|
||||
|
||||
$from = $attrs['from'];
|
||||
$item = $this->_dequote($attrs['item']);
|
||||
if (isset($attrs['name']))
|
||||
$name = $attrs['name'];
|
||||
|
||||
$output = '<?php ';
|
||||
if (isset($name)) {
|
||||
$output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n";
|
||||
$foreach_props = "\$this->_foreach[$name]";
|
||||
}
|
||||
|
||||
$key_part = '';
|
||||
|
||||
@@ -584,6 +583,7 @@ class Smarty_Compiler extends Smarty {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($name)) {
|
||||
$output .= "{$foreach_props}['total'] = count((array)$from);\n";
|
||||
$output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n";
|
||||
$output .= "if ({$foreach_props}['show']):\n";
|
||||
@@ -592,6 +592,10 @@ class Smarty_Compiler extends Smarty {
|
||||
$output .= " {$foreach_props}['iteration']++;\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 .= '?>';
|
||||
|
||||
return $output;
|
||||
|
Reference in New Issue
Block a user