From 9bcd117ecd5db0a1be8ef3d62fdb38aa1bf539fa Mon Sep 17 00:00:00 2001 From: mohrt Date: Thu, 20 Feb 2003 21:59:09 +0000 Subject: [PATCH] add get_config_vars() method, update get_template_vars() functionality --- NEWS | 4 ++++ Smarty.class.php | 28 +++++++++++++++++++++++++--- libs/Smarty.class.php | 28 +++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 8f85256e..1ad7dbc9 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ + - added get_config_vars(), same basic functionality as + get_template_vars() (Monte) + - update get_template_vars() to be able to get + individual vars (Monte) - fix minor logic in _fetch_template_info (Dennis Gearon, Monte) - fix cache groups with compile_id set (Monte) diff --git a/Smarty.class.php b/Smarty.class.php index 7d1bbf95..dc15943b 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1001,13 +1001,35 @@ class Smarty /** * Returns an array containing template variables * - * @return array + * @param string $name + * @param string $type + * @return mixed */ - function &get_template_vars() + function &get_template_vars($name=null) { - return $this->_tpl_vars; + if(!isset($name)) { + return $this->_tpl_vars; + } + if(isset($this->_tpl_vars[$name])) { + return $this->_tpl_vars[$name]; + } } + /** + * Returns an array containing config variables + * + * @param string $name + * @param string $type + * @return mixed + */ + function &get_config_vars($name=null) + { + if(!isset($name) && is_array($this->_config[0])) { + return $this->_config[0]['vars']; + } else if(isset($this->_config[0]['vars'][$name])) { + return $this->_config[0]['vars'][$name]; + } + } /** * trigger Smarty error diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 7d1bbf95..dc15943b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1001,13 +1001,35 @@ class Smarty /** * Returns an array containing template variables * - * @return array + * @param string $name + * @param string $type + * @return mixed */ - function &get_template_vars() + function &get_template_vars($name=null) { - return $this->_tpl_vars; + if(!isset($name)) { + return $this->_tpl_vars; + } + if(isset($this->_tpl_vars[$name])) { + return $this->_tpl_vars[$name]; + } } + /** + * Returns an array containing config variables + * + * @param string $name + * @param string $type + * @return mixed + */ + function &get_config_vars($name=null) + { + if(!isset($name) && is_array($this->_config[0])) { + return $this->_config[0]['vars']; + } else if(isset($this->_config[0]['vars'][$name])) { + return $this->_config[0]['vars'][$name]; + } + } /** * trigger Smarty error