4 * Smarty Method AppendByRef
6 * Smarty::appendByRef() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_AppendByRef
16 * appends values to template variables by reference
18 * @api Smarty::appendByRef()
19 * @link http://www.smarty.net/docs/en/api.append.by.ref.tpl
21 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
22 * @param string $tpl_var the template variable name
23 * @param mixed &$value the referenced value to append
24 * @param bool $merge flag if array elements shall be merged
26 * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
28 public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false)
30 if ($tpl_var != '' && isset($value)) {
31 if (!isset($data->tpl_vars[ $tpl_var ])) {
32 $data->tpl_vars[ $tpl_var ] = new Smarty_Variable();
34 if (!is_array($data->tpl_vars[ $tpl_var ]->value)) {
35 settype($data->tpl_vars[ $tpl_var ]->value, 'array');
37 if ($merge && is_array($value)) {
38 foreach ($value as $_key => $_val) {
39 $data->tpl_vars[ $tpl_var ]->value[ $_key ] = &$value[ $_key ];
42 $data->tpl_vars[ $tpl_var ]->value[] = &$value;
44 if ($data->_isTplObj() && $data->scope) {
45 $data->ext->_updateScope->_updateScope($data, $tpl_var);