mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 10:33:08 +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);
|
$tmp = $context->get($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$context->push($context->last());
|
||||||
if ($tmp) {
|
if ($tmp) {
|
||||||
$context->push($context->last());
|
|
||||||
|
|
||||||
$template->setStopToken('else');
|
$template->setStopToken('else');
|
||||||
$buffer = $template->render($context);
|
$buffer = $template->render($context);
|
||||||
$template->setStopToken(false);
|
$template->setStopToken(false);
|
||||||
$template->discard($context);
|
$template->discard($context);
|
||||||
|
|
||||||
$context->pop();
|
|
||||||
} else {
|
} else {
|
||||||
$context->push($context->last());
|
|
||||||
|
|
||||||
$template->setStopToken('else');
|
$template->setStopToken('else');
|
||||||
$template->discard($context);
|
$template->discard($context);
|
||||||
$template->setStopToken(false);
|
$template->setStopToken(false);
|
||||||
$buffer = $template->render($context);
|
$buffer = $template->render($context);
|
||||||
|
|
||||||
$context->pop();
|
|
||||||
}
|
}
|
||||||
|
$context->pop();
|
||||||
|
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
@ -962,6 +962,6 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$engine = new \Handlebars\Handlebars(array('loader' => $loader));
|
$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 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