add extra context layer for if and unless. (Toi match with handlebars.js)

This commit is contained in:
fzerorubigd 2014-08-29 11:17:31 +04:30
parent cc5bb9bf87
commit de08528c2c
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A
2 changed files with 3 additions and 9 deletions

View File

@ -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;
}

View File

@ -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')));
}
}