1 <?php
3 /**
4 * Smarty method Get_Template_Vars
5 *
6 * Returns a single or all template variables
7 *
8 * @package Smarty
9 * @subpackage SmartyMethod
10 * @author Uwe Tews
11 */
13 /**
14 * Returns a single or all template variables
15 */
17 /**
18 * Returns a single or all template variables
19 *
20 * @param string $varname variable name or null
21 * @return string variable value or or array of variables
22 */
23 function Smarty_Method_Get_Template_Vars($smarty, $varname = null, $_ptr = null, $search_parents = true)
24 {
25 if (isset($varname)) {
26 $_var = $smarty->getVariable($varname, $_ptr, $search_parents);
27 if (is_object($_var)) {
28 return $_var->value;
29 } else {
30 return null;
31 }
32 } else {
33 $_result = array();
34 if ($_ptr === null) {
35 $_ptr = $smarty;
36 } while ($_ptr !== null) {
37 foreach ($_ptr->tpl_vars AS $key => $var) {
38 $_result[$key] = $var->value;
39 }
40 // not found, try at parent
41 if ($search_parents) {
42 $_ptr = $_ptr->parent;
43 } else {
44 $_ptr = null;
45 }
46 }
47 if ($search_parents) {
48 foreach ($smarty->global_tpl_vars AS $key => $var) {
49 $_result[$key] = $var->value;
50 }
51 }
52 return $_result;
53 }
54 }
56 ?>