* the odd and even filters are now tests:
{{ foo|odd }} must now be written {{ foo is odd }}
+ * added a "constant" test
* fixed objects with __toString() not being autoescaped
* fixed subscript expressions when calling __call() (methods now keep the case)
* added a "trans" filter
the foo attribute really is the `false` PHP value
{% endif %}
+### `constant`
+
+`constant` checks if a variable has the exact same value as a constant. You
+can use either global constants or class constants:
+
+ [twig]
+ {% if post.status is constant('Post::PUBLISHED') %}
+ the status attribute is exactly the same as Post::PUBLISHED
+ {% endif %}
+
Extensions
----------
'sameas' => new Twig_Test_Function('twig_test_sameas'),
'none' => new Twig_Test_Function('twig_test_none'),
'divisibleby' => new Twig_Test_Function('twig_test_divisibleby'),
+ 'constant' => new Twig_Test_Function('twig_test_constant'),
);
}
{
return $value % 2 == 1;
}
+
+function twig_test_constant($value, $constant)
+{
+ return constant($constant) === $value;
+}
--- /dev/null
+--TEST--
+"const" test
+--TEMPLATE--
+{{ 30719 is constant('E_ALL') ? 'ok' : 'no' }}
+{{ 'bar' is constant('Foo::BAR_NAME') ? 'ok' : 'no' }}
+{{ value is constant('Foo::BAR_NAME') ? 'ok' : 'no' }}
+--DATA--
+return array('value' => 'bar');
+--EXPECT--
+ok
+ok
+ok
\ No newline at end of file
class Foo
{
+ const BAR_NAME = 'bar';
+
public function bar($param1 = null, $param2 = null)
{
return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : '');