- improvement new Smarty::$extends_recursion property to disable execution of {extends} in templates called by extends resource

https://github.com/smarty-php/smarty/issues/296
This commit is contained in:
uwetews
2016-09-30 02:30:39 +02:00
parent 68ab01dc9e
commit 80af6ea2b5
3 changed files with 5 additions and 4 deletions

View File

@@ -37,10 +37,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
$uid = ''; $uid = '';
$sources = array(); $sources = array();
$components = explode('|', $source->name); $components = explode('|', $source->name);
$smarty = &$source->smarty;
$exists = true; $exists = true;
foreach ($components as $component) { foreach ($components as $component) {
/* @var \Smarty_Template_Source $_s */ /* @var \Smarty_Template_Source $_s */
$_s = Smarty_Template_Source::load(null, $source->smarty, $component); $_s = Smarty_Template_Source::load(null, $smarty, $component);
if ($_s->type == 'php') { if ($_s->type == 'php') {
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type"); throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
} }
@@ -85,7 +86,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
public function getContent(Smarty_Template_Source $source) public function getContent(Smarty_Template_Source $source)
{ {
if (!$source->exists) { if (!$source->exists) {
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'");
} }
$_components = array_reverse($source->components); $_components = array_reverse($source->components);

View File

@@ -87,7 +87,7 @@ class Smarty_Internal_Runtime_GetIncludePath
$_dirs = (array) explode(PATH_SEPARATOR, $_i_path); $_dirs = (array) explode(PATH_SEPARATOR, $_i_path);
foreach ($_dirs as $_path) { foreach ($_dirs as $_path) {
if (is_dir($_path)) { if (is_dir($_path)) {
$this->_include_dirs[] = $smarty->_realpath($_path . $smarty->ds, true); $this->_include_dirs[] = $smarty->_realpath($_path . $smarty->ds);
} }
} }
return true; return true;

View File

@@ -111,7 +111,7 @@ class Smarty_Internal_Runtime_Inheritance
ob_end_clean(); ob_end_clean();
$this->state = 2; $this->state = 2;
} }
if (isset($template) && ($tpl->parent->source->type !== 'extends' || $tpl->smarty->extends_recursion)) { if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends') || $tpl->smarty->extends_recursion)) {
$tpl->_subTemplateRender($template, $tpl->cache_id, $tpl->compile_id, $tpl->caching ? 9999 : 0, $tpl->_subTemplateRender($template, $tpl->cache_id, $tpl->compile_id, $tpl->caching ? 9999 : 0,
$tpl->cache_lifetime, array(), 2, false, $uid, $func); $tpl->cache_lifetime, array(), 2, false, $uid, $func);
} }