* 0.9.5-DEV
* added the in operator (as a syntactic sugar for the in filter)
- * added the following filters in the Core extension: in
+ * added the following filters in the Core extension: in, range
* 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
>A sequence can be either an array or an object implementing the `Iterator`
>interface.
+If you do need to iterate over a sequence of numbers, you can use the `range`
+filter:
+
+ [twig]
+ {% for i in 0|range(10) %}
+ * {{ i }}
+ {% endfor %}
+
+The above snippet of code would print all numbers from 0 to 9 (the high value
+is never part of the generated array).
+
Inside of a `for` loop block you can access some special variables:
| Variable | Description
TRUE
{% endif %}
+### `range`
+
+Returns a list containing a sequence of numbers. The filtered value represents
+the low value and the filter takes two arguments: the first one is mandatory
+are represents the high value, and the second one is optional and represents
+the step (which defaults to `1`).
+
+If you do need to iterate over a sequence of numbers:
+
+ [twig]
+ {% for i in 0|range(10) %}
+ * {{ i }}
+ {% endfor %}
+
+>**TIP**
+>The `range` filter works as the native PHP `range` function.
+
### `default`
The `default` filter returns the passed default value if the value is
'length' => array('twig_length_filter', false),
'sort' => array('twig_sort_filter', false),
'in' => array('twig_in_filter', false),
+ 'range' => array('twig_range_filter', false),
// iteration and runtime
'default' => array('twig_default_filter', false),
return false;
}
+function twig_range_filter($start, $end, $step = 1)
+{
+ return range($start, $end, $step);
+}
+
/*
* 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