mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
support merging appended vars
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,5 +1,5 @@
|
||||
- fix cache groups with compile_id set (Monte)
|
||||
- add support for appending key=>value vars (messju, Monte)
|
||||
- add support for merging appended vars (messju, Monte)
|
||||
- change embedded variable logic to only recognize $foo and
|
||||
$foo[0][bar] and $smarty.foo.bar syntax (Monte)
|
||||
- allow null as function attribute value
|
||||
|
@@ -578,11 +578,10 @@ class Smarty
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($tpl_var != '') {
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* assigns values to template variables by reference
|
||||
@@ -602,18 +601,21 @@ class Smarty
|
||||
* @param array|string $tpl_var the template variable name(s)
|
||||
* @param mixed $value the value to append
|
||||
*/
|
||||
function append($tpl_var, $value = null)
|
||||
function append($tpl_var, $value=null, $merge=false)
|
||||
{
|
||||
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');
|
||||
// $tpl_var is an array, ignore $value
|
||||
foreach ($tpl_var as $_key => $_val) {
|
||||
if ($_key != '') {
|
||||
if(!@is_array($this->_tpl_vars[$_key])) {
|
||||
settype($this->_tpl_vars[$_key],'array');
|
||||
}
|
||||
if($merge && is_array($_val)) {
|
||||
foreach($_val as $_mkey => $_mval) {
|
||||
$this->_tpl_vars[$_key][$_mkey] = $_mval;
|
||||
}
|
||||
if(@is_array($val)) {
|
||||
$this->_tpl_vars[$key] = array_merge($this->_tpl_vars[$key],$val);
|
||||
} else {
|
||||
$this->_tpl_vars[$key][] = $val;
|
||||
$this->_tpl_vars[$_key][] = $_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -622,8 +624,10 @@ class Smarty
|
||||
if(!@is_array($this->_tpl_vars[$tpl_var])) {
|
||||
settype($this->_tpl_vars[$tpl_var],'array');
|
||||
}
|
||||
if(@is_array($value)) {
|
||||
$this->_tpl_vars[$tpl_var] = array_merge($this->_tpl_vars[$tpl_var],$value);
|
||||
if($merge && is_array($value)) {
|
||||
foreach($value as $_mkey => $_mval) {
|
||||
$this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
|
||||
}
|
||||
} else {
|
||||
$this->_tpl_vars[$tpl_var][] = $value;
|
||||
}
|
||||
@@ -637,15 +641,21 @@ class Smarty
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $value the referenced value to append
|
||||
*/
|
||||
function append_by_ref($tpl_var, &$value)
|
||||
function append_by_ref($tpl_var, &$value, $merge=false)
|
||||
{
|
||||
if ($tpl_var != '' && isset($value)) {
|
||||
if(!@is_array($this->_tpl_vars[$tpl_var])) {
|
||||
settype($this->_tpl_vars[$tpl_var],'array');
|
||||
}
|
||||
if ($merge && is_array($value)) {
|
||||
foreach($value as $_key => $_val) {
|
||||
$this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
|
||||
}
|
||||
} else {
|
||||
$this->_tpl_vars[$tpl_var][] = &$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -578,11 +578,10 @@ class Smarty
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($tpl_var != '') {
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* assigns values to template variables by reference
|
||||
@@ -602,18 +601,21 @@ class Smarty
|
||||
* @param array|string $tpl_var the template variable name(s)
|
||||
* @param mixed $value the value to append
|
||||
*/
|
||||
function append($tpl_var, $value = null)
|
||||
function append($tpl_var, $value=null, $merge=false)
|
||||
{
|
||||
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');
|
||||
// $tpl_var is an array, ignore $value
|
||||
foreach ($tpl_var as $_key => $_val) {
|
||||
if ($_key != '') {
|
||||
if(!@is_array($this->_tpl_vars[$_key])) {
|
||||
settype($this->_tpl_vars[$_key],'array');
|
||||
}
|
||||
if($merge && is_array($_val)) {
|
||||
foreach($_val as $_mkey => $_mval) {
|
||||
$this->_tpl_vars[$_key][$_mkey] = $_mval;
|
||||
}
|
||||
if(@is_array($val)) {
|
||||
$this->_tpl_vars[$key] = array_merge($this->_tpl_vars[$key],$val);
|
||||
} else {
|
||||
$this->_tpl_vars[$key][] = $val;
|
||||
$this->_tpl_vars[$_key][] = $_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -622,8 +624,10 @@ class Smarty
|
||||
if(!@is_array($this->_tpl_vars[$tpl_var])) {
|
||||
settype($this->_tpl_vars[$tpl_var],'array');
|
||||
}
|
||||
if(@is_array($value)) {
|
||||
$this->_tpl_vars[$tpl_var] = array_merge($this->_tpl_vars[$tpl_var],$value);
|
||||
if($merge && is_array($value)) {
|
||||
foreach($value as $_mkey => $_mval) {
|
||||
$this->_tpl_vars[$tpl_var][$_mkey] = $_mval;
|
||||
}
|
||||
} else {
|
||||
$this->_tpl_vars[$tpl_var][] = $value;
|
||||
}
|
||||
@@ -637,15 +641,21 @@ class Smarty
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed $value the referenced value to append
|
||||
*/
|
||||
function append_by_ref($tpl_var, &$value)
|
||||
function append_by_ref($tpl_var, &$value, $merge=false)
|
||||
{
|
||||
if ($tpl_var != '' && isset($value)) {
|
||||
if(!@is_array($this->_tpl_vars[$tpl_var])) {
|
||||
settype($this->_tpl_vars[$tpl_var],'array');
|
||||
}
|
||||
if ($merge && is_array($value)) {
|
||||
foreach($value as $_key => $_val) {
|
||||
$this->_tpl_vars[$tpl_var][$_key] = &$value[$_key];
|
||||
}
|
||||
} else {
|
||||
$this->_tpl_vars[$tpl_var][] = &$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user