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