mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
move getTemplateVars() into data object
This commit is contained in:
2
README
2
README
@@ -54,6 +54,7 @@ $smarty->getConfigVariable($variable)
|
||||
$smarty->getStreamVariable($variable)
|
||||
$smarty->getConfigVars($varname = null)
|
||||
$smarty->clearConfig($varname = null)
|
||||
$smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
|
||||
// some API calls are moved into their own objects:
|
||||
|
||||
@@ -87,7 +88,6 @@ $smarty->unregister->variableFilter($function_name)
|
||||
|
||||
$smarty->utility->compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
|
||||
$smarty->utility->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
|
||||
$smarty->utility->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
$smarty->utility->testInstall()
|
||||
|
||||
// then all the getters/setters, available for all properties. Here are a few:
|
||||
|
@@ -158,6 +158,45 @@ class Smarty_Internal_Data {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single or all template variables
|
||||
*
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
$_var = $this->getVariable($varname, $_ptr, $search_parents);
|
||||
if (is_object($_var)) {
|
||||
return $_var->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $this;
|
||||
} while ($_ptr !== null) {
|
||||
foreach ($_ptr->tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
// not found, try at parent
|
||||
if ($search_parents) {
|
||||
$_ptr = $_ptr->parent;
|
||||
} else {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if ($search_parents) {
|
||||
foreach ($this->global_tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
}
|
||||
return $_result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the given assigned template variable.
|
||||
*
|
||||
|
@@ -154,45 +154,6 @@ class Smarty_Internal_Utility {
|
||||
return $_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single or all template variables
|
||||
*
|
||||
* @param string $varname variable name or null
|
||||
* @return string variable value or or array of variables
|
||||
*/
|
||||
function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
|
||||
{
|
||||
if (isset($varname)) {
|
||||
$_var = $this->smarty->getVariable($varname, $_ptr, $search_parents);
|
||||
if (is_object($_var)) {
|
||||
return $_var->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$_result = array();
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $this->smarty;
|
||||
} while ($_ptr !== null) {
|
||||
foreach ($_ptr->tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
// not found, try at parent
|
||||
if ($search_parents) {
|
||||
$_ptr = $_ptr->parent;
|
||||
} else {
|
||||
$_ptr = null;
|
||||
}
|
||||
}
|
||||
if ($search_parents) {
|
||||
foreach ($this->smarty->global_tpl_vars AS $key => $var) {
|
||||
$_result[$key] = $var->value;
|
||||
}
|
||||
}
|
||||
return $_result;
|
||||
}
|
||||
}
|
||||
|
||||
function testInstall()
|
||||
{
|
||||
echo "<PRE>\n";
|
||||
|
Reference in New Issue
Block a user