diff --git a/sandbox/fenom.php b/sandbox/fenom.php index c525228..81e18de 100644 --- a/sandbox/fenom.php +++ b/sandbox/fenom.php @@ -6,7 +6,8 @@ require_once __DIR__.'/../tests/tools.php'; \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled'); -$fenom->setOptions(Fenom::AUTO_RELOAD); -var_dump($fenom->compileCode('{set $z = "A"~~"B"}')->getBody()); -//$fenom->display("blocks/second.tpl", []); +$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_COMPILE); +//var_dump($fenom->compileCode('{set $z = "A"~~"B"}')->getBody()); +//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode()); +var_dump($fenom->display("bug158/main.tpl", [])); // $fenom->getTemplate("problem.tpl"); \ No newline at end of file diff --git a/sandbox/templates/bug158/main.tpl b/sandbox/templates/bug158/main.tpl new file mode 100644 index 0000000..7c89662 --- /dev/null +++ b/sandbox/templates/bug158/main.tpl @@ -0,0 +1,3 @@ +{* Отображаемый шаблон *} +{import [test] from "bug158/test.tpl" as test} +{test.test} \ No newline at end of file diff --git a/sandbox/templates/bug158/test.tpl b/sandbox/templates/bug158/test.tpl new file mode 100644 index 0000000..76b9343 --- /dev/null +++ b/sandbox/templates/bug158/test.tpl @@ -0,0 +1,7 @@ +{* template:test.tpl *} +{macro test($break = false)} + Test macro recursive +{if $break?} + {macro.test break = true} +{/if} +{/macro} \ No newline at end of file diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 31e961f..9f00ec1 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -428,9 +428,9 @@ class Template extends Render { if ($this->macros) { $macros = array(); - foreach ($this->macros as $m) { + foreach ($this->macros as $name => $m) { if ($m["recursive"]) { - $macros[] = "\t\t'" . $m["name"] . "' => function (\$var, \$tpl) {\n?>" . $m["body"] . " function (\$var, \$tpl) {\n?>" . $m["body"] . "macros[$name])) { $macro = $this->macros[$name]; $recursive = $macro['recursive']; diff --git a/tests/cases/Fenom/MacrosTest.php b/tests/cases/Fenom/MacrosTest.php index 129e370..89ff81d 100644 --- a/tests/cases/Fenom/MacrosTest.php +++ b/tests/cases/Fenom/MacrosTest.php @@ -77,34 +77,12 @@ class MacrosTest extends TestCase $this->tpl( "macro_recursive_import.tpl", ' - {import "macro_recursive.tpl" as math} + {import [factorial] from "macro_recursive.tpl" as math} {math.factorial num=10}' ); } - public function _testSandbox() - { - try { -// $this->fenom->compile("macro_recursive.tpl")->display([]); -// $this->fenom->flush(); -// var_dump($this->fenom->fetch("macro_recursive.tpl", [])); - var_dump( - $this->fenom->compileCode( - '{macro factorial(num)} - {if $num} - {$num} {macro.factorial num=$num-1} {$num} - {/if} - {/macro}' - )->getBody() - ); -// var_dump($this->fenom->display("macro_recursive_import.tpl", array())); - } catch (\Exception $e) { - var_dump($e->getMessage() . ": " . $e->getTraceAsString()); - } - exit; - } - /** * @throws \Exception * @group macros @@ -162,6 +140,7 @@ class MacrosTest extends TestCase $this->assertSame("10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10", Modifier::strip($tpl->fetch(array()), true)); } + public function testImportRecursive() { $this->fenom->compile('macro_recursive_import.tpl');