diff --git a/NEW_FEATURES.txt b/NEW_FEATURES.txt index 6603244e..bddc631f 100644 --- a/NEW_FEATURES.txt +++ b/NEW_FEATURES.txt @@ -2,7 +2,20 @@ 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 ========================================= {block_parent} == {$smarty.block.parent} diff --git a/change_log.txt b/change_log.txt index 4ed9ff20..f5e7c950 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,6 +2,8 @@ 19.5.2017 - change properties $accessMap and $obsoleteProperties from private to protected 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 - fix spelling https://github.com/smarty-php/smarty/commit/e3eda8a5f5653d8abb960eb1bc47e3eca679b1b4#commitcomment-21803095 diff --git a/libs/sysplugins/smarty_internal_compile_capture.php b/libs/sysplugins/smarty_internal_compile_capture.php index 34fc55f9..73c8a2ce 100644 --- a/libs/sysplugins/smarty_internal_compile_capture.php +++ b/libs/sysplugins/smarty_internal_compile_capture.php @@ -45,11 +45,11 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) { $tag = trim($parameter[ 0 ], '"\''); - $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false; + $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : null; 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}')":')'); } /** diff --git a/libs/sysplugins/smarty_internal_runtime_capture.php b/libs/sysplugins/smarty_internal_runtime_capture.php index 69f1ce0c..18da7e8a 100644 --- a/libs/sysplugins/smarty_internal_runtime_capture.php +++ b/libs/sysplugins/smarty_internal_runtime_capture.php @@ -64,7 +64,9 @@ class Smarty_Internal_Runtime_Capture if (!$this->isRegistered) { $this->register($_template); } - $this->captureStack[] = array($buffer, $assign, $append); + $this->captureStack[] = array($buffer, + $assign, + $append); $this->captureCount ++; ob_start(); } @@ -76,8 +78,10 @@ class Smarty_Internal_Runtime_Capture */ private function register(Smarty_Internal_Template $_template) { - $_template->startRenderCallbacks[] = array($this, 'startRender'); - $_template->endRenderCallbacks[] = array($this, 'endRender'); + $_template->startRenderCallbacks[] = array($this, + 'startRender'); + $_template->endRenderCallbacks[] = array($this, + 'endRender'); $this->startRender($_template); $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 $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; + } } /**