Merge pull request #139 from fenom-template/develop

Fix #138
This commit is contained in:
Ivan Shalganov 2015-01-30 16:56:37 +03:00
commit dd6986b60f
5 changed files with 19 additions and 4 deletions

View File

@ -7,5 +7,6 @@ require_once __DIR__.'/../tests/tools.php';
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
$fenom->setOptions(Fenom::AUTO_RELOAD);
$fenom->display(["blocks/body.tpl", "layout.tpl"], []);
var_dump($fenom->compile("blocks/second.tpl", false)->getBody());
//$fenom->display("blocks/second.tpl", []);
// $fenom->getTemplate("problem.tpl");

View File

@ -0,0 +1,6 @@
{* main.tpl *}
{extends 'blocks/root.tpl'}
{block 'header'}
{parent}
main header
{/block}

View File

@ -0,0 +1,4 @@
{* root.tpl *}
{block 'header'}
root header
{/block}

View File

@ -0,0 +1,6 @@
{* second.tpl *}
{extends 'blocks/main.tpl'}
{block 'header'}
{parent}
second header
{/block}

View File

@ -589,12 +589,10 @@ class Compiler
{
$tpl = $scope->tpl;
$name = $scope["name"];
if (isset($tpl->blocks[$name])) { // block defined
$block = & $tpl->blocks[$name];
if ($block['use_parent']) {
$parent = $scope->getContent();
$block['block'] = str_replace($block['use_parent'] . " ?>", "?>" . $parent, $block['block']);
}
if (!$block["import"]) { // not from {use} - redefine block
@ -625,7 +623,7 @@ class Compiler
{
$block_scope = $scope->tpl->getParentScope('block');
if (!$block_scope['use_parent']) {
$block_scope['use_parent'] = "/* %%parent#" . mt_rand(0, 1e6) . "%% */";
$block_scope['use_parent'] = "/* %%parent#{$scope['name']}%% */";
}
return $block_scope['use_parent'];
}