support appending key=>val pairs

This commit is contained in:
mohrt
2003-02-19 16:40:13 +00:00
parent 2cd256d4fc
commit 212a27346e
3 changed files with 41 additions and 18 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- add support for appending key=>value vars (messju, Monte)
- change embedded variable logic to only recognize $foo and
$foo[0][bar] syntax (Monte)
- allow null as function attribute value

View File

@@ -600,16 +600,20 @@ class Smarty
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param mixed $key the key of value to append
*/
function append($tpl_var, $value = null)
function append($tpl_var, $value = null, $key=null)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $key => $val) {
if ($key != '') {
if(!@is_array($this->_tpl_vars[$key])) {
settype($this->_tpl_vars[$key],'array');
foreach ($tpl_var as $name=>$val) {
if ($var_name != '') {
if(!@is_array($this->_tpl_vars[$name])) {
settype($this->_tpl_vars[$name],'array');
}
$this->_tpl_vars[$key][] = $val;
if (isset($key))
$this->_tpl_vars[$name][$key] = $val;
else
$this->_tpl_vars[$name][] = $val;
}
}
} else {
@@ -617,6 +621,9 @@ class Smarty
if(!@is_array($this->_tpl_vars[$tpl_var])) {
settype($this->_tpl_vars[$tpl_var],'array');
}
if (isset($key))
$this->_tpl_vars[$tpl_var][$key] = $value;
else
$this->_tpl_vars[$tpl_var][] = $value;
}
}
@@ -627,13 +634,17 @@ class Smarty
*
* @param string $tpl_var the template variable name
* @param mixed $value the referenced value to append
* @param mixed $key the key of value to append
*/
function append_by_ref($tpl_var, &$value)
function append_by_ref($tpl_var, &$value, $key=null)
{
if ($tpl_var != '' && isset($value)) {
if(!@is_array($this->_tpl_vars[$tpl_var])) {
settype($this->_tpl_vars[$tpl_var],'array');
}
if (isset($key))
$this->_tpl_vars[$tpl_var][$key] = &$value;
else
$this->_tpl_vars[$tpl_var][] = &$value;
}
}

View File

@@ -600,16 +600,20 @@ class Smarty
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param mixed $key the key of value to append
*/
function append($tpl_var, $value = null)
function append($tpl_var, $value = null, $key=null)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $key => $val) {
if ($key != '') {
if(!@is_array($this->_tpl_vars[$key])) {
settype($this->_tpl_vars[$key],'array');
foreach ($tpl_var as $name=>$val) {
if ($var_name != '') {
if(!@is_array($this->_tpl_vars[$name])) {
settype($this->_tpl_vars[$name],'array');
}
$this->_tpl_vars[$key][] = $val;
if (isset($key))
$this->_tpl_vars[$name][$key] = $val;
else
$this->_tpl_vars[$name][] = $val;
}
}
} else {
@@ -617,6 +621,9 @@ class Smarty
if(!@is_array($this->_tpl_vars[$tpl_var])) {
settype($this->_tpl_vars[$tpl_var],'array');
}
if (isset($key))
$this->_tpl_vars[$tpl_var][$key] = $value;
else
$this->_tpl_vars[$tpl_var][] = $value;
}
}
@@ -627,13 +634,17 @@ class Smarty
*
* @param string $tpl_var the template variable name
* @param mixed $value the referenced value to append
* @param mixed $key the key of value to append
*/
function append_by_ref($tpl_var, &$value)
function append_by_ref($tpl_var, &$value, $key=null)
{
if ($tpl_var != '' && isset($value)) {
if(!@is_array($this->_tpl_vars[$tpl_var])) {
settype($this->_tpl_vars[$tpl_var],'array');
}
if (isset($key))
$this->_tpl_vars[$tpl_var][$key] = &$value;
else
$this->_tpl_vars[$tpl_var][] = &$value;
}
}