mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-11-04 04:05:07 +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
 | 
			
		||||
 * @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