From 62039b5e2491eb0079ce42a9cd586090f219664a Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Sun, 12 Apr 2009 02:30:54 +0000 Subject: [PATCH] - added append and prepend attribute to {block} tag --- change_log.txt | 3 +++ libs/sysplugins/internal.compile_block.php | 2 +- .../internal.compile_blockclose.php | 6 ++++- libs/sysplugins/internal.compile_extend.php | 26 ++++++++++++------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/change_log.txt b/change_log.txt index e2d8e8e3..2580c56b 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,6 @@ +04/12/2009 +- added append and prepend attribute to {block} tag + 04/11/2009 - fixed variables in 'file' attribute of {extend} tag - fixed problems in modifiers (if mb string functions not present) diff --git a/libs/sysplugins/internal.compile_block.php b/libs/sysplugins/internal.compile_block.php index 67077ada..b4092eb3 100644 --- a/libs/sysplugins/internal.compile_block.php +++ b/libs/sysplugins/internal.compile_block.php @@ -23,7 +23,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { { $this->compiler = $compiler; $this->required_attributes = array('name'); - $this->optional_attributes = array('assign'); + $this->optional_attributes = array('assign','append','prepend'); // check and get attributes $_attr = $this->_get_attributes($args); $save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code); diff --git a/libs/sysplugins/internal.compile_blockclose.php b/libs/sysplugins/internal.compile_blockclose.php index befed4bb..7cc00611 100644 --- a/libs/sysplugins/internal.compile_blockclose.php +++ b/libs/sysplugins/internal.compile_blockclose.php @@ -34,7 +34,11 @@ class Smarty_Internal_Compile_BlockClose extends Smarty_Internal_CompileBase { $this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"'); } $_name = trim($saved_data[0]['name'], "'"); - if (!empty($compiler->template->block_data[$_name])) { + if (isset($saved_data[0]['append'])) { + $_output = $compiler->template->block_data[$_name]['compiled'].$compiler->template->extracted_compiled_code; + } elseif (isset($saved_data[0]['prepend'])) { + $_output = $compiler->template->extracted_compiled_code.$compiler->template->block_data[$_name]['compiled']; + } elseif (!empty($compiler->template->block_data[$_name])) { $_output = $compiler->template->block_data[$_name]['compiled']; } else { $_output = $compiler->template->extracted_compiled_code; diff --git a/libs/sysplugins/internal.compile_extend.php b/libs/sysplugins/internal.compile_extend.php index 5536fb17..4754d167 100644 --- a/libs/sysplugins/internal.compile_extend.php +++ b/libs/sysplugins/internal.compile_extend.php @@ -27,8 +27,8 @@ class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); $_smarty_tpl = $compiler->template; -// $include_file = ''; - eval('$include_file = '.$_attr['file'].';'); + // $include_file = ''; + eval('$include_file = ' . $_attr['file'] . ';'); // create template object $_template = new Smarty_Template ($include_file, $compiler->template); // save file dependency @@ -43,17 +43,25 @@ class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase { protected function saveBlockData(array $matches) { - if (0 == preg_match('/(.?)(name=)(.*)/', $matches[2], $_match)) { + if (0 == preg_match('/(.?)(name=)([^ ]*)/', $matches[2], $_match)) { $this->compiler->trigger_template_error("\"" . $matches[0] . "\" missing name attribute"); } else { + // compile block content + $tpl = $this->smarty->createTemplate('string:' . $matches[3]); + $tpl->suppressHeader = true; + $compiled_content = $tpl->getCompiledTemplate(); + $tpl->suppressHeader = false; $_name = trim($_match[3], "\"'"); - if (!isset($this->compiler->template->block_data[$_name])) { - // compile block content - $tpl = $this->smarty->createTemplate('string:' . $matches[3]); - $tpl->suppressHeader = true; - $this->compiler->template->block_data[$_name]['compiled'] = $tpl->getCompiledTemplate(); + + if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) { + $this->compiler->template->block_data[$_name]['compiled'] .= $compiled_content; + $this->compiler->template->block_data[$_name]['source'] .= $matches[3]; + } elseif (preg_match('/(.?)(prepend=true)(.*)/', $matches[2], $_match) != 0) { + $this->compiler->template->block_data[$_name]['compiled'] = $compiled_content . $this->compiler->template->block_data[$_name]['compiled']; + $this->compiler->template->block_data[$_name]['source'] = $matches[3] . $this->compiler->template->block_data[$_name]['source']; + } elseif (!isset($this->compiler->template->block_data[$_name])) { + $this->compiler->template->block_data[$_name]['compiled'] = $compiled_content; $this->compiler->template->block_data[$_name]['source'] = $matches[3]; - $tpl->suppressHeader = false; } } }