4 * Smarty Method GetTemplateVars
6 * Smarty::getTemplateVars() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_GetTemplateVars
15 * Valid for all objects
22 * Returns a single or all template variables
24 * @api Smarty::getTemplateVars()
25 * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
27 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
28 * @param string $varName variable name or null
29 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
30 * @param bool $searchParents include parent templates?
32 * @return mixed variable value or or array of variables
34 public function getTemplateVars(Smarty_Internal_Data $data, $varName = null, Smarty_Internal_Data $_ptr = null,
35 $searchParents = true)
37 if (isset($varName)) {
38 $_var = $this->_getVariable($data, $varName, $_ptr, $searchParents, false);
39 if (is_object($_var)) {
49 while ($_ptr !== null) {
50 foreach ($_ptr->tpl_vars AS $key => $var) {
51 if (!array_key_exists($key, $_result)) {
52 $_result[ $key ] = $var->value;
55 // not found, try at parent
57 $_ptr = $_ptr->parent;
62 if ($searchParents && isset(Smarty::$global_tpl_vars)) {
63 foreach (Smarty::$global_tpl_vars AS $key => $var) {
64 if (!array_key_exists($key, $_result)) {
65 $_result[ $key ] = $var->value;
74 * gets the object of a Smarty variable
76 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
77 * @param string $varName the name of the Smarty variable
78 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
79 * @param bool $searchParents search also in parent data
80 * @param bool $errorEnable
82 * @return \Smarty_Variable
84 public function _getVariable(Smarty_Internal_Data $data, $varName, Smarty_Internal_Data $_ptr = null,
85 $searchParents = true, $errorEnable = true)
90 while ($_ptr !== null) {
91 if (isset($_ptr->tpl_vars[ $varName ])) {
92 // found it, return it
93 return $_ptr->tpl_vars[ $varName ];
95 // not found, try at parent
97 $_ptr = $_ptr->parent;
102 if (isset(Smarty::$global_tpl_vars[ $varName ])) {
103 // found it, return it
104 return Smarty::$global_tpl_vars[ $varName ];
106 /* @var \Smarty $smarty */
107 $smarty = isset($data->smarty) ? $data->smarty : $data;
108 if ($smarty->error_unassigned && $errorEnable) {
113 return new Smarty_Undefined_Variable;