mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
Added template_exists() API.
This commit is contained in:
1
NEWS
1
NEWS
@@ -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)
|
||||||
|
@@ -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;
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user