mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Merge pull request #36 from cgray/master
Add support for .length on arrays
This commit is contained in:
commit
ab2d5adbb6
@ -9,7 +9,7 @@
|
||||
* @package Handlebars
|
||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||
* @author Behrooz Shabani <everplays@gmail.com>
|
||||
* @author Chris Gray <chrisgray@gmail.com>
|
||||
* @author Chris Gray <chris.w.gray@gmail.com>
|
||||
* @copyright 2012 (c) ParsPooyesh Co
|
||||
* @copyright 2013 (c) Behrooz Shabani
|
||||
* @copyright 2013 (c) f0ruD A
|
||||
@ -261,6 +261,8 @@ class Context
|
||||
} elseif (is_array($variable)) {
|
||||
if (isset($variable[$inside])) {
|
||||
return $variable[$inside];
|
||||
} elseif ($inside == "length") {
|
||||
return count($variable);
|
||||
}
|
||||
} elseif (is_object($variable)) {
|
||||
if (isset($variable->$inside)) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @package Handlebars
|
||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||
* @author Behrooz Shabani <everplays@gmail.com>
|
||||
* @author Chris Gray <chrisgray@gmail.com>
|
||||
* @author Chris Gray <chris.w.gray@gmail.com>
|
||||
* @copyright 2012 (c) ParsPooyesh Co
|
||||
* @copyright 2013 (c) Behrooz Shabani
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
|
@ -80,6 +80,16 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||
array('data' => array('key' => 'result')),
|
||||
'result'
|
||||
),
|
||||
array(
|
||||
'{{data.length}}',
|
||||
array("data" => array(1,2,3,4)),
|
||||
'4'
|
||||
),
|
||||
array(
|
||||
'{{data.length}}',
|
||||
array("data"=> (object)array(1,2,3,4)),
|
||||
''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user