Changes:
+ * added the "empty" test
+
* 0.9.10 (2010-12-16)
Backward incompatibilities:
...
{% endif %}
+``empty``
+~~~~~~~~~
+
+``empty`` checks if a variable is empty:
+
+.. code-block:: jinja
+
+ {# evaluates to true if the foo variable is null, false, or the empty string #}
+ {% if foo is empty %}
+ ...
+ {% endif %}
+
Extensions
----------
'none' => new Twig_Test_Function('twig_test_none'),
'divisibleby' => new Twig_Test_Function('twig_test_divisibleby'),
'constant' => new Twig_Test_Function('twig_test_constant'),
+ 'empty' => new Twig_Test_Function('twig_test_empty'),
);
}
{
return array_key_exists($name, $context);
}
+
+function twig_test_empty($value)
+{
+ return null === $value || false === $value || '' === (string) $value;
+}
--- /dev/null
+--TEST--
+"empty" test
+--TEMPLATE--
+{{ foo is empty ? 'ok' : 'ko' }}
+{{ bar is empty ? 'ok' : 'ko' }}
+{{ foobar is empty ? 'ok' : 'ko' }}
+--DATA--
+return array('foo' => '', 'bar' => null, 'foobar' => false);
+--EXPECT--
+ok
+ok
+ok