+++ /dev/null
-``array``
-=========
-
-``array`` checks if a variable is an array:
-
-.. code-block:: jinja
-
- {# evaluates to true if the foo variable is an array #}
- {% if foo is array %}
- ...
- {% endif %}
constant
defined
empty
+ iterable
--- /dev/null
+``iterable``
+============
+
+``iterable`` checks if a variable is an array or a traversable object:
+
+.. code-block:: jinja
+
+ {# evaluates to true if the foo variable is iterable #}
+ {% if foo is iterable %}
+ ...
+ {% endif %}
+++ /dev/null
-``traversable``
-=========
-
-``traversable`` checks if a variable is an array or a traversable object:
-
-.. code-block:: jinja
-
- {# evaluates to true if the foo variable is traversable #}
- {% if foo is traversable %}
- ...
- {% endif %}
'divisibleby' => new Twig_Test_Node('Twig_Node_Expression_Test_Divisibleby'),
'constant' => new Twig_Test_Node('Twig_Node_Expression_Test_Constant'),
'empty' => new Twig_Test_Function('twig_test_empty'),
- 'array' => new Twig_Test_Function('is_array'),
- 'traversable' => new Twig_Test_Function('twig_test_traversable'),
+ 'iterable' => new Twig_Test_Function('twig_test_iterable'),
);
}
*
* @return Boolean true if the value is traversable
*/
-function twig_test_traversable($value)
+function twig_test_iterable($value)
{
return $value instanceof Traversable || is_array($value);
}
+++ /dev/null
---TEST--
-"is_array" test
---TEMPLATE--
-{{ foo is array ? 'ok' : 'ko' }}
-{{ obj is array ? 'ok' : 'ko' }}
-{{ val is array ? 'ok' : 'ko' }}
---DATA--
-return array(
- 'foo' => array(),
- 'obj' => new stdClass(),
- 'val' => 'test',
-);
---EXPECT--
-ok
-ko
-ko
\ No newline at end of file
--TEST--
-"traversable" test
+"iterable" test
--TEMPLATE--
-{{ foo is traversable ? 'ok' : 'ko' }}
-{{ traversable is traversable ? 'ok' : 'ko' }}
-{{ obj is traversable ? 'ok' : 'ko' }}
-{{ val is traversable ? 'ok' : 'ko' }}
+{{ foo is iterable ? 'ok' : 'ko' }}
+{{ traversable is iterable ? 'ok' : 'ko' }}
+{{ obj is iterable ? 'ok' : 'ko' }}
+{{ val is iterable ? 'ok' : 'ko' }}
--DATA--
return array(
'foo' => array(),