- new feature {parent} = {$smarty.block.parent} {child} = {$smarty.block.child}

This commit is contained in:
Uwe Tews
2018-03-26 22:35:31 +02:00
parent c81948d602
commit 0dbace8321
14 changed files with 2012 additions and 1707 deletions
@@ -42,11 +42,10 @@ class Smarty_Internal_Runtime_Inheritance
*
* @var int
*/
public $tplIndex = -1;
public $tplIndex = - 1;
/**
* Array of template source objects
* - key template index
*
* @var Smarty_Template_Source[]
*/
@@ -75,7 +74,7 @@ class Smarty_Internal_Runtime_Inheritance
$tpl->inheritance->init($tpl, $initChild, $blockNames);
return;
}
$this->tplIndex++;
++$this->tplIndex;
$this->sources[ $this->tplIndex ] = $tpl->source;
// start of child sub template(s)
@@ -85,7 +84,7 @@ class Smarty_Internal_Runtime_Inheritance
//grab any output of child templates
ob_start();
}
$this->inheritanceLevel++;
++$this->inheritanceLevel;
// $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
// $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
}
@@ -109,7 +108,7 @@ class Smarty_Internal_Runtime_Inheritance
*/
public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null)
{
$this->inheritanceLevel--;
--$this->inheritanceLevel;
if (!$this->inheritanceLevel) {
ob_end_clean();
$this->state = 2;
@@ -167,8 +166,7 @@ class Smarty_Internal_Runtime_Inheritance
*
* @throws \SmartyException
*/
public function process(Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block,
Smarty_Internal_Block $parent = null)
{
if ($block->hide && !isset($block->child)) {
@@ -179,7 +177,7 @@ class Smarty_Internal_Runtime_Inheritance
}
$block->parent = $parent;
if ($block->append && !$block->prepend && isset($parent)) {
$this->callParent($tpl, $block);
$this->callParent($tpl, $block, '\'{block append}\'');
}
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
$this->callBlock($block, $tpl);
@@ -187,7 +185,7 @@ class Smarty_Internal_Runtime_Inheritance
$this->process($tpl, $block->child, $block);
}
if ($block->prepend && isset($parent)) {
$this->callParent($tpl, $block);
$this->callParent($tpl, $block, '{block prepend}');
if ($block->append) {
if ($block->callsChild || !isset($block->child) ||
($block->child->hide && !isset($block->child->child))
@@ -202,70 +200,42 @@ class Smarty_Internal_Runtime_Inheritance
}
/**
* Render child on $smarty.block.child
* Render child on \$smarty.block.child
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty_Internal_Block $block
* @param boolean $returnContent flag if content shall be returned
*
* @return null|string null or block content dependent on $returnContent
* @return null|string block content
* @throws \SmartyException
*/
public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $returnContent = false)
public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
{
if ($returnContent) {
ob_start();
}
if (isset($block->child)) {
$this->process($tpl, $block->child, $block);
}
if ($returnContent) {
return ob_get_clean();
}
return;
}
/**
* Render parent block on $smarty.block.parent or {block append/prepend}
* Render parent block on \$smarty.block.parent or {block append/prepend}
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty_Internal_Block $block
* @param null|string $name
* @param boolean $returnContent flag if content shall be returned
* @param string $tag
*
* @return null|string null or block content dependent on $returnContent
* @return null|string block content
* @throws \SmartyException
*/
public function callParent(Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
$name = null,
$returnContent = false)
public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $tag)
{
if ($returnContent) {
ob_start();
}
if (isset($name)) {
$block = $block->parent;
while (isset($block)) {
if (isset($block->subBlocks[ $name ])) {
} else {
$block = $block->parent;
}
}
return;
} else if (isset($block->parent)) {
if (isset($block->parent)) {
$this->callBlock($block->parent, $tpl);
} else {
throw new SmartyException("inheritance: illegal '\$smarty.block.parent' or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
throw new SmartyException("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
}
if ($returnContent) {
return ob_get_clean();
}
return;
}
/**
* redender block
* render block
*
* @param \Smarty_Internal_Block $block
* @param \Smarty_Internal_Template $tpl