- update on append and prepend attribute at {block} tag

This commit is contained in:
Uwe.Tews
2009-04-12 05:40:30 +00:00
parent 62039b5e24
commit bdb43faab3
3 changed files with 15 additions and 6 deletions

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','append','prepend');
$this->optional_attributes = array('assign');
// check and get attributes
$_attr = $this->_get_attributes($args);
$save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code);

View File

@@ -34,9 +34,9 @@ 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 (isset($saved_data[0]['append'])) {
if ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
$_output = $compiler->template->block_data[$_name]['compiled'].$compiler->template->extracted_compiled_code;
} elseif (isset($saved_data[0]['prepend'])) {
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
$_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'];

View File

@@ -26,7 +26,7 @@ class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase {
$this->required_attributes = array('file');
// check and get attributes
$_attr = $this->_get_attributes($args);
$_smarty_tpl = $compiler->template;
$_smarty_tpl = $compiler->template;
// $include_file = '';
eval('$include_file = ' . $_attr['file'] . ';');
// create template object
@@ -53,16 +53,25 @@ class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase {
$tpl->suppressHeader = false;
$_name = trim($_match[3], "\"'");
if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) {
if ($this->compiler->template->block_data[$_name]['mode'] == 'prepend') {
$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) {
} elseif ($this->compiler->template->block_data[$_name]['mode'] == 'append') {
$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];
}
if ($this->compiler->template->block_data[$_name]['mode'] != 'replace') {
if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) {
$this->compiler->template->block_data[$_name]['mode'] = 'append';
} elseif (preg_match('/(.?)(prepend=true)(.*)/', $matches[2], $_match) != 0) {
$this->compiler->template->block_data[$_name]['mode'] = 'prepend';
} else {
$this->compiler->template->block_data[$_name]['mode'] = 'replace';
}
}
}
}
}