53 public function assign($tpl_var, $value = null, $nocache =
false)
55 if (is_array($tpl_var)) {
56 foreach ($tpl_var as $_key => $_val) {
79 public function assignGlobal($varname, $value = null, $nocache =
false)
104 if ($tpl_var !=
'') {
106 $this->tpl_vars[$tpl_var]->value = &$value;
122 public function append($tpl_var, $value = null, $merge =
false, $nocache =
false)
124 if (is_array($tpl_var)) {
126 foreach ($tpl_var as $_key => $_val) {
128 if (!isset($this->tpl_vars[$_key])) {
129 $tpl_var_inst = $this->
getVariable($_key, null,
true,
false);
133 $this->tpl_vars[$_key] = clone $tpl_var_inst;
136 if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
137 settype($this->tpl_vars[$_key]->value,
'array');
139 if ($merge && is_array($_val)) {
140 foreach ($_val as $_mkey => $_mval) {
141 $this->tpl_vars[$_key]->value[$_mkey] = $_mval;
144 $this->tpl_vars[$_key]->value[] = $_val;
149 if ($tpl_var !=
'' && isset($value)) {
150 if (!isset($this->tpl_vars[$tpl_var])) {
151 $tpl_var_inst = $this->
getVariable($tpl_var, null,
true,
false);
155 $this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
158 if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
159 settype($this->tpl_vars[$tpl_var]->value,
'array');
161 if ($merge && is_array($value)) {
162 foreach ($value as $_mkey => $_mval) {
163 $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
166 $this->tpl_vars[$tpl_var]->value[] = $value;
185 if ($tpl_var !=
'' && isset($value)) {
186 if (!isset($this->tpl_vars[$tpl_var])) {
189 if (!is_array($this->tpl_vars[$tpl_var]->value)) {
190 settype($this->tpl_vars[$tpl_var]->value,
'array');
192 if ($merge && is_array($value)) {
193 foreach ($value as $_key => $_val) {
194 $this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
197 $this->tpl_vars[$tpl_var]->value[] = &$value;
213 public function getTemplateVars($varname = null, $_ptr = null, $search_parents =
true)
215 if (isset($varname)) {
216 $_var = $this->
getVariable($varname, $_ptr, $search_parents,
false);
217 if (is_object($_var)) {
224 if ($_ptr === null) {
227 while ($_ptr !== null) {
228 foreach ($_ptr->tpl_vars AS $key => $var) {
229 if (!array_key_exists($key, $_result)) {
230 $_result[$key] = $var->value;
234 if ($search_parents) {
235 $_ptr = $_ptr->parent;
242 if (!array_key_exists($key, $_result)) {
243 $_result[$key] = $var->value;
261 if (is_array($tpl_var)) {
262 foreach ($tpl_var as $curr_var) {
263 unset($this->tpl_vars[$curr_var]);
266 unset($this->tpl_vars[$tpl_var]);
279 $this->tpl_vars = array();
309 public function getVariable($variable, $_ptr = null, $search_parents =
true, $error_enable =
true)
311 if ($_ptr === null) {
314 while ($_ptr !== null) {
315 if (isset($_ptr->tpl_vars[$variable])) {
317 return $_ptr->tpl_vars[$variable];
320 if ($search_parents) {
321 $_ptr = $_ptr->parent;
330 $smarty = isset($this->smarty) ? $this->smarty : $this;
331 if ($smarty->error_unassigned && $error_enable) {
388 $fp = fopen($variable,
'r+');
390 while (!feof($fp) && ($current_line = fgets($fp)) !==
false) {
391 $_result .= $current_line;
397 $smarty = isset($this->smarty) ? $this->smarty : $this;
398 if ($smarty->error_unassigned) {
399 throw new SmartyException(
'Undefined stream variable "' . $variable .
'"');