mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
add extra context layer for if and unless. (Toi match with handlebars.js)
This commit is contained in:
parent
cc5bb9bf87
commit
de08528c2c
@ -56,25 +56,19 @@ class IfHelper implements Helper
|
||||
$tmp = $context->get($args);
|
||||
}
|
||||
|
||||
$context->push($context->last());
|
||||
if ($tmp) {
|
||||
$context->push($context->last());
|
||||
|
||||
$template->setStopToken('else');
|
||||
$buffer = $template->render($context);
|
||||
$template->setStopToken(false);
|
||||
$template->discard($context);
|
||||
|
||||
$context->pop();
|
||||
} else {
|
||||
$context->push($context->last());
|
||||
|
||||
$template->setStopToken('else');
|
||||
$template->discard($context);
|
||||
$template->setStopToken(false);
|
||||
$buffer = $template->render($context);
|
||||
|
||||
$context->pop();
|
||||
}
|
||||
$context->pop();
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
@ -962,6 +962,6 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||
$engine = new \Handlebars\Handlebars(array('loader' => $loader));
|
||||
|
||||
$this->assertEquals('good', $engine->render('{{#with b}}{{#if this}}{{../../a}}{{/if}}{{/with}}', array('a' => 'good', 'b' => 'stump')));
|
||||
$this->assertEquals('good', $engine->render('{{#with b}}{{#if unless}}{{else}}{{../../a}}{{/if}}{{/with}}', array('a' => 'good', 'b' => 'stump')));
|
||||
$this->assertEquals('good', $engine->render('{{#with b}}{{#unless false}}{{../../a}}{{/unless}}{{/with}}', array('a' => 'good', 'b' => 'stump')));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user