mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- bugfix template objects must be cached on $smarty->fetch('foo.tpl) calls incase the template is fetched
multiple times (forum topic 25909)
This commit is contained in:
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/50';
|
||||
const SMARTY_VERSION = '3.1.30-dev/51';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
@@ -1046,23 +1046,23 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId =
|
||||
$this->_getTemplateId($template, $cache_id, $compile_id) ])
|
||||
) {
|
||||
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
|
||||
$tpl = null;
|
||||
if ($this->caching && isset($this->_cache[ 'isCached' ][ $_templateId ])) {
|
||||
$tpl = $do_clone ? clone $this->_cache[ 'isCached' ][ $_templateId ] :
|
||||
$this->_cache[ 'isCached' ][ $_templateId ];
|
||||
$tpl->parent = $parent;
|
||||
$tpl->tpl_vars = array();
|
||||
$tpl->config_vars = array();
|
||||
$template->tpl_vars = $template->config_vars = array();
|
||||
} else if (!$do_clone && isset($this->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||
$tpl = clone $this->_cache[ 'tplObjects' ][ $_templateId ];
|
||||
} else {
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id, null, null);
|
||||
$tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
|
||||
$tpl->templateId = $_templateId;
|
||||
}
|
||||
if ($do_clone) {
|
||||
$tpl->smarty = clone $tpl->smarty;
|
||||
} elseif ($parent === null) {
|
||||
$tpl->parent = $this;
|
||||
}
|
||||
$tpl->parent = $parent ? $parent : $this;
|
||||
// fill data if present
|
||||
if (!empty($data) && is_array($data)) {
|
||||
// set up variable values
|
||||
|
@@ -155,14 +155,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$isCacheTpl =
|
||||
$this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
||||
if ($isCacheTpl) {
|
||||
if (!isset($this->cached)) {
|
||||
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id ||
|
||||
$this->cached->compile_id !== $this->compile_id
|
||||
) {
|
||||
$this->loadCached();
|
||||
}
|
||||
$this->cached->render($this, $no_output_filter);
|
||||
} elseif ($this->source->handler->uncompiled) {
|
||||
$this->source->render($this);
|
||||
} else {
|
||||
if (!isset($this->compiled)) {
|
||||
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
|
||||
$this->loadCompiled();
|
||||
}
|
||||
$this->compiled->render($this);
|
||||
|
@@ -148,23 +148,24 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
||||
private function _execute($template, $cache_id, $compile_id, $parent, $function)
|
||||
{
|
||||
$smarty = $this->_objType == 1 ? $this : $this->smarty;
|
||||
$saveVars = true;
|
||||
if ($template === null) {
|
||||
if ($this->_objType != 2) {
|
||||
throw new SmartyException($function . '():Missing \'$template\' parameter');
|
||||
} else {
|
||||
$template = clone $this;
|
||||
$template = $this;
|
||||
}
|
||||
} elseif (is_object($template)) {
|
||||
if (!isset($template->_objType) || $template->_objType != 2) {
|
||||
throw new SmartyException($function . '():Template object expected');
|
||||
} else {
|
||||
/* @var Smarty_Internal_Template $template */
|
||||
$template = clone $template;
|
||||
}
|
||||
} else {
|
||||
// get template object
|
||||
/* @var Smarty_Internal_Template $template */
|
||||
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
||||
$saveVars = false;
|
||||
|
||||
$template =
|
||||
$smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
|
||||
if ($this->_objType == 1) {
|
||||
// set caching in template object
|
||||
$template->caching = $this->caching;
|
||||
@@ -187,12 +188,28 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($saveVars) {
|
||||
$savedTplVars = $template->tpl_vars;
|
||||
$savedConfigVars = $template->config_vars;
|
||||
}
|
||||
ob_start();
|
||||
$template->_mergeVars();
|
||||
if (!empty(Smarty::$global_tpl_vars)) {
|
||||
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
|
||||
}
|
||||
$result = $template->render(false, $function);
|
||||
unset($template->ext->_inheritance);
|
||||
$template->tpl_function = array();
|
||||
if ($saveVars) {
|
||||
$template->tpl_vars = $savedTplVars;
|
||||
$template->config_vars = $savedConfigVars;
|
||||
} else {
|
||||
if (!$function && !isset($smarty->_cache[ 'tplObjects' ][ $template->templateId ])) {
|
||||
$template->parent = null;
|
||||
$template->tpl_vars = $template->config_vars = array();
|
||||
$smarty->_cache[ 'tplObjects' ][ $template->templateId ] = $template;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_smarty_old_error_level)) {
|
||||
error_reporting($_smarty_old_error_level);
|
||||
|
Reference in New Issue
Block a user