- template inheritance: child templates can now call functions defined by the {function} tag in the parent template

This commit is contained in:
Uwe.Tews
2009-12-03 19:49:17 +00:00
parent 2c23dccf3b
commit 91da0aa7fe
4 changed files with 35 additions and 48 deletions
@@ -63,22 +63,20 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
}
$_name = trim($saved_data[0]['name'], "\"'");
if (isset($this->smarty->block_data[$_name])) {
if (strpos($this->smarty->block_data[$_name]['compiled'], '%%%%SMARTY_PARENT%%%%') !== false) {
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $this->smarty->block_data[$_name]['compiled']);
$_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template);
$_tpl->template_filepath = $this->smarty->block_data[$_name]['file'];
$_tpl->forceNocache = true;
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $_tpl->getCompiledTemplate());
} elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
$_output = $this->smarty->block_data[$_name]['compiled'] . $compiler->template->extracted_compiled_code;
$_output = $_tpl->getCompiledTemplate() . $compiler->template->extracted_compiled_code;
} elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
$_output = $compiler->template->extracted_compiled_code . $this->smarty->block_data[$_name]['compiled'];
$_output = $compiler->template->extracted_compiled_code . $_tpl->getCompiledTemplate();
} elseif (!empty($this->smarty->block_data[$_name])) {
$_output = $this->smarty->block_data[$_name]['compiled'];
}
if (isset($this->smarty->block_data[$_name]['function'])) {
if (isset($compiler->template->properties['function'])) {
$compiler->template->properties['function'] = array_merge ($compiler->template->properties['function'], $this->smarty->block_data[$_name]['function']);
} else {
$compiler->template->properties['function'] = $this->smarty->block_data[$_name]['function'];
}
$_output = $_tpl->getCompiledTemplate();
}
unset($tpl);
} else {
$_output = $compiler->template->extracted_compiled_code;
}