mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 02:26:41 +03:00
Add "else" block to "unless" helper
This commit is contained in:
parent
c83e0fbbf7
commit
c5d6a482c1
10
src/Handlebars/Helpers.php
Executable file → Normal file
10
src/Handlebars/Helpers.php
Executable file → Normal file
@ -9,6 +9,7 @@
|
|||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
* @author Behrooz Shabani <everplays@gmail.com>
|
* @author Behrooz Shabani <everplays@gmail.com>
|
||||||
|
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||||
* @copyright 2012 (c) ParsPooyesh Co
|
* @copyright 2012 (c) ParsPooyesh Co
|
||||||
* @copyright 2013 (c) Behrooz Shabani
|
* @copyright 2013 (c) Behrooz Shabani
|
||||||
* @license MIT <http://opensource.org/licenses/MIT>
|
* @license MIT <http://opensource.org/licenses/MIT>
|
||||||
@ -150,8 +151,15 @@ class Helpers
|
|||||||
* @var $source string
|
* @var $source string
|
||||||
*/
|
*/
|
||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$buffer = '';
|
|
||||||
if (!$tmp) {
|
if (!$tmp) {
|
||||||
|
$template->setStopToken('else');
|
||||||
|
$buffer = $template->render($context);
|
||||||
|
$template->setStopToken(false);
|
||||||
|
} else {
|
||||||
|
$template->setStopToken('else');
|
||||||
|
$template->discard();
|
||||||
|
$template->setStopToken(false);
|
||||||
$buffer = $template->render($context);
|
$buffer = $template->render($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
* @category Xamin
|
* @category Xamin
|
||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
|
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||||
* @copyright 2013 (c) f0ruD A
|
* @copyright 2013 (c) f0ruD A
|
||||||
* @license MIT <http://opensource.org/licenses/MIT>
|
* @license MIT <http://opensource.org/licenses/MIT>
|
||||||
* @version GIT: $Id$
|
* @version GIT: $Id$
|
||||||
@ -172,6 +173,16 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('data' => false),
|
array('data' => false),
|
||||||
'ok'
|
'ok'
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'{{#unless data}}ok{{else}}fail{{/unless}}',
|
||||||
|
array('data' => false),
|
||||||
|
'ok'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'{{#unless data}}fail{{else}}ok{{/unless}}',
|
||||||
|
array('data' => true),
|
||||||
|
'ok'
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'{{#bindAttr data}}',
|
'{{#bindAttr data}}',
|
||||||
array(),
|
array(),
|
||||||
|
Loading…
Reference in New Issue
Block a user