Added template_exists() API.

This commit is contained in:
andrei
2002-04-03 19:31:11 +00:00
parent dd56027476
commit 21c65f93e6
3 changed files with 21 additions and 6 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- added template_exists() API function. (Andrei)
- fixed a problem with using dynamic values for 'file' - fixed a problem with using dynamic values for 'file'
attribute of {include_php} tag. (Andrei) attribute of {include_php} tag. (Andrei)
- added $smarty.template variable. (Andrei) - added $smarty.template variable. (Andrei)

View File

@@ -469,6 +469,11 @@ class Smarty
return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id); return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id);
} }
function template_exists($tpl_file)
{
return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true);
}
/*======================================================================*\ /*======================================================================*\
Function: get_template_vars Function: get_template_vars
Purpose: Returns an array containing template variables Purpose: Returns an array containing template variables
@@ -881,7 +886,7 @@ function _generate_debug_output() {
Purpose: fetch the template info. Gets timestamp, and source Purpose: fetch the template info. Gets timestamp, and source
if get_source is true if get_source is true
\*======================================================================*/ \*======================================================================*/
function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true) function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false)
{ {
$_return = false; $_return = false;
if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) { if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) {
@@ -924,9 +929,11 @@ function _generate_debug_output() {
} }
if (!$_return) { if (!$_return) {
$this->trigger_error("unable to read template resource: \"$tpl_path\""); if (!$quiet)
$this->trigger_error("unable to read template resource: \"$tpl_path\"");
} else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) { } else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) {
$this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); if (!$quiet)
$this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed");
$template_source = null; $template_source = null;
$template_timestamp = null; $template_timestamp = null;
return false; return false;

View File

@@ -469,6 +469,11 @@ class Smarty
return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id); return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id);
} }
function template_exists($tpl_file)
{
return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true);
}
/*======================================================================*\ /*======================================================================*\
Function: get_template_vars Function: get_template_vars
Purpose: Returns an array containing template variables Purpose: Returns an array containing template variables
@@ -881,7 +886,7 @@ function _generate_debug_output() {
Purpose: fetch the template info. Gets timestamp, and source Purpose: fetch the template info. Gets timestamp, and source
if get_source is true if get_source is true
\*======================================================================*/ \*======================================================================*/
function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true) function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false)
{ {
$_return = false; $_return = false;
if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) { if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) {
@@ -924,9 +929,11 @@ function _generate_debug_output() {
} }
if (!$_return) { if (!$_return) {
$this->trigger_error("unable to read template resource: \"$tpl_path\""); if (!$quiet)
$this->trigger_error("unable to read template resource: \"$tpl_path\"");
} else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) { } else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) {
$this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); if (!$quiet)
$this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed");
$template_source = null; $template_source = null;
$template_timestamp = null; $template_timestamp = null;
return false; return false;