- bugfix nested block tags in template inheritance child templates did not work correctly

- bugfix {$smarty.current_dir} in child template did not point to dir of child template
This commit is contained in:
uwe.tews@googlemail.com
2010-12-11 13:27:14 +00:00
parent ea37403f01
commit cf50ede71a
3 changed files with 12 additions and 17 deletions

View File

@@ -1,4 +1,8 @@
===== SVN trunk ===== ===== SVN trunk =====
11/12/2010
- bugfix nested block tags in template inheritance child templates did not work correctly
- bugfix {$smarty.current_dir} in child template did not point to dir of child template
06/12/2010 06/12/2010
- bugfix getTemplateVars() should return 'null' instead dropping E_NOTICE on an unassigned variable - bugfix getTemplateVars() should return 'null' instead dropping E_NOTICE on an unassigned variable

View File

@@ -46,7 +46,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
static function saveBlockData($block_content, $block_tag, $template, $filepath) static function saveBlockData($block_content, $block_tag, $template, $filepath)
{ {
$_rdl = preg_quote($template->smarty->right_delimiter); $_rdl = preg_quote($template->smarty->right_delimiter);
$_ldl = preg_quote($template->smarty->left_delimiter); $_ldl = preg_quote($template->smarty->left_delimiter);
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)(=true)?)?(\s*{$_rdl})!", $block_tag, $_match)) { if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)(=true)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
@@ -85,7 +85,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$template->block_data[$_name]['mode'] = 'replace'; $template->block_data[$_name]['mode'] = 'replace';
} }
$template->block_data[$_name]['file'] = $filepath; $template->block_data[$_name]['file'] = $filepath;
} }
} }
static function compileChildBlock ($compiler, $_name = null) static function compileChildBlock ($compiler, $_name = null)
@@ -100,6 +100,8 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
break; break;
} }
} }
// flag that child is already compile by {$smarty.block.child} inclusion
$compiler->template->block_data[$_name]['compiled'] = true;
} }
if ($_name == null) { if ($_name == null) {
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $this->compiler->lex->taglineno); $compiler->trigger_template_error('{$smarty.block.child} used out of context', $this->compiler->lex->taglineno);
@@ -108,7 +110,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
if (!isset($compiler->template->block_data[$_name])) { if (!isset($compiler->template->block_data[$_name])) {
return ''; return '';
} }
$_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime); $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->template_filepath = $compiler->template->block_data[$_name]['file']; $_tpl->template_filepath = $compiler->template->block_data[$_name]['file'];
@@ -141,7 +143,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
} }
} }
unset($_tpl); unset($_tpl);
$compiler->template->block_data[$_name]['compiled'] = true;
return $_output; return $_output;
} }
@@ -172,7 +173,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
} else { } else {
$_output = $compiler->parser->current_buffer->to_smarty_php(); $_output = $compiler->parser->current_buffer->to_smarty_php();
unset ($compiler->template->block_data[$_name]['compiled']); unset ($compiler->template->block_data[$_name]['compiled']);
} }
// reset flags // reset flags
$compiler->parser->current_buffer = $saved_data[1]; $compiler->parser->current_buffer = $saved_data[1];
$compiler->nocache = $saved_data[2]; $compiler->nocache = $saved_data[2];

View File

@@ -56,21 +56,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
break; break;
case 'template': case 'template':
if ($compiler->smarty->inheritance) { $_template_name = $compiler->template->template_resource;
$ptr = $compiler->template->parent;
} else {
$ptr = $compiler->template;
}
$_template_name = $ptr->template_resource;
return "'$_template_name'"; return "'$_template_name'";
case 'current_dir': case 'current_dir':
if ($compiler->smarty->inheritance) { $_template_dir_name = dirname($compiler->template->getTemplateFilepath());
$ptr = $compiler->template->parent;
} else {
$ptr = $compiler->template;
}
$_template_dir_name = dirname($ptr->getTemplateFilepath());
return "'$_template_dir_name'"; return "'$_template_dir_name'";
case 'version': case 'version':