mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #75 for new inheritance system
This commit is contained in:
parent
654b259b42
commit
218efdffe6
@ -13,7 +13,7 @@ namespace {
|
||||
|
||||
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled', Fenom::FORCE_COMPILE);
|
||||
|
||||
$fenom->display("greeting.tpl", array(
|
||||
$fenom->display("extends/75-child.tpl", array(
|
||||
"user" => array(
|
||||
"name" => "Ivka",
|
||||
'type' => 'new'
|
||||
|
13
sandbox/templates/extends/75-child.tpl
Normal file
13
sandbox/templates/extends/75-child.tpl
Normal file
@ -0,0 +1,13 @@
|
||||
{extends 'extends/75-parent.tpl'}
|
||||
{block 'child'}
|
||||
{macro child_test(v, i)}
|
||||
child test - {$v}, i = {$i};<br/>
|
||||
{var $i = $i -1}
|
||||
{if $i > 0}
|
||||
{macro.child_test v=$v i=$i}
|
||||
{/if}
|
||||
{/macro}
|
||||
|
||||
child call: <br/>
|
||||
{macro.child_test v = 'ok' i = 5}
|
||||
{/block}
|
12
sandbox/templates/extends/75-parent.tpl
Normal file
12
sandbox/templates/extends/75-parent.tpl
Normal file
@ -0,0 +1,12 @@
|
||||
{macro parent_test(v, i)}
|
||||
parent test - {$v}, i = {$i};<br/>
|
||||
{var $i = $i -1}
|
||||
{if $i > 0}
|
||||
{macro.parent_test v=$v i=$i}
|
||||
{/if}
|
||||
{/macro}
|
||||
|
||||
{block 'child'}{/block}
|
||||
|
||||
parent call:<br/>
|
||||
{macro.parent_test v = 'ok' i = 5} <br/>
|
@ -741,6 +741,7 @@ class Fenom
|
||||
public function getTemplate($template, $options = 0)
|
||||
{
|
||||
$options |= $this->_options;
|
||||
// var_dump($this->_options & self::FORCE_COMPILE);
|
||||
if (is_array($template)) {
|
||||
$key = dechex($options) . "@" . implode(",", $template);
|
||||
} else {
|
||||
@ -755,6 +756,7 @@ class Fenom
|
||||
return $tpl;
|
||||
}
|
||||
} elseif ($this->_options & self::FORCE_COMPILE) {
|
||||
|
||||
return $this->compile($template, $this->_options & self::DISABLE_CACHE & ~self::FORCE_COMPILE, $options);
|
||||
} else {
|
||||
return $this->_storage[$key] = $this->_load($template, $options);
|
||||
|
@ -202,7 +202,7 @@ class Render extends \ArrayObject
|
||||
public function getMacro($name)
|
||||
{
|
||||
if (empty($this->_macros[$name])) {
|
||||
throw new \RuntimeException('macro not found');
|
||||
throw new \RuntimeException('macro '.$name.' not found');
|
||||
}
|
||||
return $this->_macros[$name];
|
||||
}
|
||||
|
@ -471,6 +471,7 @@ class Template extends Render
|
||||
{
|
||||
if (!$this->_code) {
|
||||
// evaluate template's code
|
||||
var_dump($this->_getClosureSource(), $this->_getMacrosArray());
|
||||
eval("\$this->_code = " . $this->_getClosureSource() . ";\n\$this->_macros = " . $this->_getMacrosArray() . ';');
|
||||
if (!$this->_code) {
|
||||
throw new CompileException("Fatal error while creating the template");
|
||||
@ -532,6 +533,7 @@ class Template extends Render
|
||||
}
|
||||
$parent = $this->_fenom->getRawTemplate()->load($tpl, false);
|
||||
$parent->blocks = & $this->blocks;
|
||||
$parent->macros = & $this->macros;
|
||||
$parent->extended = $this->getName();
|
||||
if (!$this->ext_stack) {
|
||||
$this->ext_stack[] = $this->getName();
|
||||
@ -1379,10 +1381,10 @@ class Template extends Render
|
||||
}
|
||||
}
|
||||
if ($recursive) {
|
||||
$body = '$tpl->getMacro("' . $name . '")->__invoke($tpl);';
|
||||
if($recursive instanceof Scope) {
|
||||
$recursive['recursive'] = true;
|
||||
}
|
||||
return '$tpl->getMacro("' . $name . '")->__invoke('.Compiler::toArray($args).', $tpl);';
|
||||
} else {
|
||||
$vars = $this->tmpVar();
|
||||
return $vars . ' = $var; $var = ' . Compiler::toArray($args) . ';' . PHP_EOL . '?>' .
|
||||
|
Loading…
Reference in New Issue
Block a user