* the odd and even filters are now tests:
{{ foo|odd }} must now be written {{ foo is odd }}
+ * added a "constant" filter
* added a "constant" test
* fixed objects with __toString() not being autoescaped
* fixed subscript expressions when calling __call() (methods now keep the case)
{{ var|safe }} {# var won't be escaped #}
{% autoescape off %}
+### `constant` (new in Twig 0.9.9)
+
+`constant` returns the constant value for a given string:
+
+ [twig]
+ {{ some_date|date('DATE_W3C'|constant) }}
+
List of built-in Tests (new in Twig 0.9.9)
------------------------------------------
'upper' => new Twig_Filter_Function('strtoupper'),
'lower' => new Twig_Filter_Function('strtolower'),
'striptags' => new Twig_Filter_Function('strip_tags'),
+ 'constant' => new Twig_Filter_Function('twig_constant_filter'),
// array helpers
'join' => new Twig_Filter_Function('twig_join_filter'),
return $values[$i % count($values)];
}
+function twig_constant_filter($constant)
+{
+ return constant($constant);
+}
+
/*
* Each type specifies a way for applying a transformation to a string
* The purpose is for the string to be "escaped" so it is suitable for
--- /dev/null
+--TEST--
+"constant" filter
+--TEMPLATE--
+{{ date|date('DATE_W3C'|constant) }}
+--DATA--
+$d = date_default_timezone_get();
+date_default_timezone_set('UTC');
+$ret = array('date' => strtotime('2005-10-15 10:00:01'));
+date_default_timezone_set($d);
+return $ret;
+--EXPECT--
+2005-10-15T10:00:01+00:00