Inherit parent vars and add own vars when a template is included with vars from another template that has vars; add unit tests for vars inheritance

This commit is contained in:
Kijin Sung 2023-10-21 13:52:02 +09:00
parent 5b47151440
commit 6085b82d19
7 changed files with 92 additions and 12 deletions

View file

@ -402,7 +402,8 @@ class TemplateParser_v2
// Generate the code to create a new Template object and compile it.
$tpl = '<?php $__tpl = new \Rhymix\Framework\Template(' . $dir . ', "' . $path . '", "' . ($this->template->extension ?: 'auto') . '"); ';
$tpl .= !empty($attrs['vars']) ? '$__tpl->setVars(' . self::_convertVariableScope($attrs['vars']) . '); ' : '';
$tpl .= 'if ($this->vars): $__tpl->setVars($this->vars); endif; ';
$tpl .= !empty($attrs['vars']) ? '$__tpl->addVars(' . self::_convertVariableScope($attrs['vars']) . '); ' : '';
$tpl .= 'echo $__tpl->compile(); ?>';
// Add conditions around the code.