- added append and prepend attribute to {block} tag

This commit is contained in:
Uwe.Tews
2009-04-12 02:30:54 +00:00
parent c9b789ca32
commit 62039b5e24
4 changed files with 26 additions and 11 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}
}
}