* included the default filter function definitions in the extension class files directly (Core, Escaper)
* added the .. operator (as a syntactic sugar for the range filter when the step is 1)
* added the in operator (as a syntactic sugar for the in filter)
- * added the following filters in the Core extension: in, range
+ * added the following filters in the Core extension: in, range, floor
* added support for arrays (same behavior as in PHP, a mix between lists and dictionaries, arrays and hashes)
* enhanced some error messages to provide better feedback in case of parsing errors
* `/`: Divide two numbers. The return value will be a floating point number.
`{{ 1 / 2 }}` is `{{ 0.5 }}`.
- * `//`: Divide two numbers and return the truncated integer result. `{{ 20 //
- 7 }}` is `2`.
-
* `%`: Calculate the remainder of an integer division. `{{ 11 % 7 }}` is `4`.
* `*`: Multiply the left operand with the right one. `{{ 2 * 2 }}` would
[twig]
{{ var|odd ? 'odd' : 'even' }}
+### `floor`
+
+The `floor` filter divides two numbers and return the truncated integer
+result
+
+ [twig]
+ {{ 20|floor(7) }} {# returns 2 #}
+
### `encoding`
The `encoding` filter URL encode a given string.
'format' => new Twig_Filter_Function('sprintf'),
// numbers
- 'even' => new Twig_Filter_Function('twig_is_even_filter'),
- 'odd' => new Twig_Filter_Function('twig_is_odd_filter'),
+ 'even' => new Twig_Filter_Function('twig_is_even_filter'),
+ 'odd' => new Twig_Filter_Function('twig_is_odd_filter'),
+ 'floor' => new Twig_Filter_Function('twig_floor_filter'),
// encoding
'urlencode' => new Twig_Filter_Function('twig_urlencode_filter'),
return $value % 2 == 1;
}
+function twig_floor_filter($value, $div)
+{
+ return floor($value / $div);
+}
+
function twig_length_filter($thing)
{
return is_string($thing) ? strlen($thing) : count($thing);