This commit is contained in:
bzick 2015-01-30 16:52:58 +03:00
parent 2f769c294c
commit e310236745
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 = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
$fenom->setOptions(Fenom::AUTO_RELOAD); $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"); // $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; $tpl = $scope->tpl;
$name = $scope["name"]; $name = $scope["name"];
if (isset($tpl->blocks[$name])) { // block defined if (isset($tpl->blocks[$name])) { // block defined
$block = & $tpl->blocks[$name]; $block = & $tpl->blocks[$name];
if ($block['use_parent']) { if ($block['use_parent']) {
$parent = $scope->getContent(); $parent = $scope->getContent();
$block['block'] = str_replace($block['use_parent'] . " ?>", "?>" . $parent, $block['block']); $block['block'] = str_replace($block['use_parent'] . " ?>", "?>" . $parent, $block['block']);
} }
if (!$block["import"]) { // not from {use} - redefine block if (!$block["import"]) { // not from {use} - redefine block
@ -625,7 +623,7 @@ class Compiler
{ {
$block_scope = $scope->tpl->getParentScope('block'); $block_scope = $scope->tpl->getParentScope('block');
if (!$block_scope['use_parent']) { 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']; return $block_scope['use_parent'];
} }