- new feature The named capture buffers can now be accessed also as array

See NEWS_FEATURES.txt https://github.com/smarty-php/smarty/issues/366
This commit is contained in:
uwetews
2017-05-19 18:44:06 +02:00
parent d571ffa111
commit 2782e83a92
4 changed files with 35 additions and 12 deletions

View File

@@ -2,7 +2,20 @@
This file contains a brief description of new features which have been added to Smarty 3.1 This file contains a brief description of new features which have been added to Smarty 3.1
Smarty 3.1.31 Smarty 3.1.32
The capture buffers can now be accessed as array
================================================
{capture name='foo'}
bah
{\capture}
{capture name='buh'}
blar
{\capture}
{foreach $smarty.capture as $name => $buffer}
....
{/foreach}
Smarty 3.1.31
New tags for inheritance parent and child New tags for inheritance parent and child
========================================= =========================================
{block_parent} == {$smarty.block.parent} {block_parent} == {$smarty.block.parent}

View File

@@ -2,6 +2,8 @@
19.5.2017 19.5.2017
- change properties $accessMap and $obsoleteProperties from private to protected - change properties $accessMap and $obsoleteProperties from private to protected
https://github.com/smarty-php/smarty/issues/351 https://github.com/smarty-php/smarty/issues/351
- improvement The named capture buffers can now be accessed also as array
See NEWS_FEATURES.txt https://github.com/smarty-php/smarty/issues/366
24.4.2017 24.4.2017
- fix spelling https://github.com/smarty-php/smarty/commit/e3eda8a5f5653d8abb960eb1bc47e3eca679b1b4#commitcomment-21803095 - fix spelling https://github.com/smarty-php/smarty/commit/e3eda8a5f5653d8abb960eb1bc47e3eca679b1b4#commitcomment-21803095

View File

@@ -45,11 +45,11 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{ {
$tag = trim($parameter[ 0 ], '"\''); $tag = trim($parameter[ 0 ], '"\'');
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false; $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null;
if (!$name) { if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); //$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
} }
return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')"; return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl'.(isset($name)?"'{$name}')":')');
} }
/** /**

View File

@@ -64,7 +64,9 @@ class Smarty_Internal_Runtime_Capture
if (!$this->isRegistered) { if (!$this->isRegistered) {
$this->register($_template); $this->register($_template);
} }
$this->captureStack[] = array($buffer, $assign, $append); $this->captureStack[] = array($buffer,
$assign,
$append);
$this->captureCount ++; $this->captureCount ++;
ob_start(); ob_start();
} }
@@ -76,8 +78,10 @@ class Smarty_Internal_Runtime_Capture
*/ */
private function register(Smarty_Internal_Template $_template) private function register(Smarty_Internal_Template $_template)
{ {
$_template->startRenderCallbacks[] = array($this, 'startRender'); $_template->startRenderCallbacks[] = array($this,
$_template->endRenderCallbacks[] = array($this, 'endRender'); 'startRender');
$_template->endRenderCallbacks[] = array($this,
'endRender');
$this->startRender($_template); $this->startRender($_template);
$this->isRegistered = true; $this->isRegistered = true;
} }
@@ -130,16 +134,20 @@ class Smarty_Internal_Runtime_Capture
} }
/** /**
* Return content of named capture buffer * Return content of named capture buffer by key or as array
* *
* @param \Smarty_Internal_Template $_template * @param \Smarty_Internal_Template $_template
* @param $name * @param string|null $name
* *
* @return null * @return string|string[]|null
*/ */
public function getBuffer(Smarty_Internal_Template $_template, $name) public function getBuffer(Smarty_Internal_Template $_template, $name = null)
{ {
return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; if (isset($name)) {
return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null;
} else {
return $this->namedBuffer;
}
} }
/** /**