diff --git a/src/Handlebars/Helpers.php b/src/Handlebars/Helpers.php old mode 100755 new mode 100644 index d22460f..1df6619 --- a/src/Handlebars/Helpers.php +++ b/src/Handlebars/Helpers.php @@ -9,6 +9,7 @@ * @package Handlebars * @author fzerorubigd * @author Behrooz Shabani + * @author Dmitriy Simushev * @copyright 2012 (c) ParsPooyesh Co * @copyright 2013 (c) Behrooz Shabani * @license 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); } diff --git a/tests/Xamin/HandlebarsTest.php b/tests/Xamin/HandlebarsTest.php index eb96579..6647a70 100644 --- a/tests/Xamin/HandlebarsTest.php +++ b/tests/Xamin/HandlebarsTest.php @@ -8,6 +8,7 @@ * @category Xamin * @package Handlebars * @author fzerorubigd + * @author Dmitriy Simushev * @copyright 2013 (c) f0ruD A * @license 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(),