* 1.13.1 (2013-XX-XX)
+ * added support for object instances as the second argument of the constant test
* fixed the include function when used in an assignment
* 1.13.0 (2013-05-10)
``constant``
============
+.. versionadded: 1.13.1
+ constant now accepts object instances as the second argument.
+
``constant`` checks if a variable has the exact same value as a constant. You
can use either global constants or class constants:
{% if post.status is constant('Post::PUBLISHED') %}
the status attribute is exactly the same as Post::PUBLISHED
{% endif %}
+
+You can test constants from object instances as well:
+
+.. code-block:: jinja
+
+ {% if post.status is constant('PUBLISHED', post) %}
+ the status attribute is exactly the same as Post::PUBLISHED
+ {% endif %}
->raw('(')
->subcompile($this->getNode('node'))
->raw(' === constant(')
+ ;
+
+ if ($this->getNode('arguments')->hasNode(1)) {
+ $compiler
+ ->raw('get_class(')
+ ->subcompile($this->getNode('arguments')->getNode(1))
+ ->raw(')."::".')
+ ;
+ }
+
+ $compiler
->subcompile($this->getNode('arguments')->getNode(0))
->raw('))')
;
{{ 8 is constant('E_NOTICE') ? 'ok' : 'no' }}
{{ 'bar' is constant('TwigTestFoo::BAR_NAME') ? 'ok' : 'no' }}
{{ value is constant('TwigTestFoo::BAR_NAME') ? 'ok' : 'no' }}
+{{ 2 is constant('ARRAY_AS_PROPS', object) ? 'ok' : 'no' }}
--DATA--
-return array('value' => 'bar');
+return array('value' => 'bar', 'object' => new ArrayObject(array('hi')));
--EXPECT--
ok
ok
+ok
ok
\ No newline at end of file