Constant | F |
Undocumented |
Constant | FILTERS |
Undocumented |
Constant | K |
Undocumented |
Constant | V |
Undocumented |
Class | _GroupTuple |
Undocumented |
Class | HasHTML |
Undocumented |
Function | _min_or_max |
Undocumented |
Function | _prepare_attribute_parts |
Undocumented |
Async Function | async_select_or_reject |
Undocumented |
Function | contextfilter |
Pass the context as the first argument to the decorated function. |
Function | do_attr |
Get an attribute of an object. foo|attr("bar") works like foo.bar just that always an attribute is returned and items are not looked up. |
Function | do_batch |
No summary |
Function | do_capitalize |
Capitalize a value. The first character will be uppercase, all others lowercase. |
Function | do_center |
Centers the value in a field of a given width. |
Function | do_default |
If the value is undefined it will return the passed default value, otherwise the value of the variable: |
Function | do_dictsort |
Sort a dict and yield (key, value) pairs. Python dicts may not be in the order you want to display them in, so sort them first. |
Function | do_filesizeformat |
No summary |
Async Function | do_first |
Undocumented |
Function | do_float |
Convert the value into a floating point number. If the conversion doesn't work it will return 0.0. You can override this default using the first parameter. |
Function | do_forceescape |
Enforce HTML escaping. This will probably double escape variables. |
Function | do_format |
Apply the given values to a `printf-style`_ format string, like string % values. |
Async Function | do_groupby |
Undocumented |
Function | do_indent |
Return a copy of the string with each line indented by 4 spaces. The first line and blank lines are not indented by default. |
Function | do_int |
No summary |
Async Function | do_join |
Undocumented |
Function | do_last |
Return the last item of a sequence. |
Async Function | do_list |
Undocumented |
Function | do_lower |
Convert a value to lowercase. |
Async Function | do_map |
Undocumented |
Function | do_mark_safe |
Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped. |
Function | do_mark_unsafe |
Mark a value as unsafe. This is the reverse operation for safe . |
Function | do_max |
Return the largest item from the sequence. |
Function | do_min |
Return the smallest item from the sequence. |
Function | do_pprint |
Pretty print a variable. Useful for debugging. |
Function | do_random |
Return a random item from the sequence. |
Async Function | do_reject |
Undocumented |
Async Function | do_rejectattr |
Undocumented |
Function | do_replace |
No summary |
Function | do_reverse |
Reverse the object or return an iterator that iterates over it the other way round. |
Function | do_round |
Round the number to a given precision. The first parameter specifies the precision (default is 0), the second the rounding method: |
Async Function | do_select |
Undocumented |
Async Function | do_selectattr |
Undocumented |
Async Function | do_slice |
Undocumented |
Function | do_sort |
Sort an iterable using Python's sorted . |
Function | do_striptags |
Strip SGML/XML tags and replace adjacent whitespace by one space. |
Async Function | do_sum |
Undocumented |
Function | do_title |
Return a titlecased version of the value. I.e. words will start with uppercase letters, all remaining characters are lowercase. |
Function | do_tojson |
Serialize an object to a string of JSON, and mark it safe to render in HTML. This filter is only for use in HTML documents. |
Function | do_trim |
Strip leading and trailing characters, by default whitespace. |
Function | do_truncate |
No summary |
Function | do_unique |
Returns a list of unique items from the given iterable. |
Function | do_upper |
Convert a value to uppercase. |
Function | do_urlencode |
Quote data for use in a URL path or query using UTF-8. |
Function | do_urlize |
Convert URLs in text into clickable links. |
Function | do_wordcount |
Count the words in that string. |
Function | do_wordwrap |
Wrap a string to the given width. Existing newlines are treated as paragraphs to be wrapped separately. |
Function | do_xmlattr |
Create an SGML/XML attribute string based on the items in a dict. All values that are neither none nor undefined are automatically escaped: |
Function | environmentfilter |
Pass the environment as the first argument to the decorated function. |
Function | evalcontextfilter |
Pass the eval context as the first argument to the decorated function. |
Function | ignore_case |
For use as a postprocessor for make_attrgetter . Converts strings to lowercase and returns other types as-is. |
Function | make_attrgetter |
No summary |
Function | make_multi_attrgetter |
No summary |
Function | prepare_map |
Undocumented |
Function | prepare_select_or_reject |
Undocumented |
Function | select_or_reject |
Undocumented |
Function | sync_do_first |
Return the first item of a sequence. |
Function | sync_do_groupby |
No summary |
Function | sync_do_join |
Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per default, you can define it with the optional parameter: |
Function | sync_do_list |
Convert the value into a list. If it was a string the returned list will be a list of characters. |
Function | sync_do_map |
Applies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with lists of objects but you are really only interested in a certain value of it. |
Function | sync_do_reject |
Filters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding. |
Function | sync_do_rejectattr |
Filters a sequence of objects by applying a test to the specified attribute of each object, and rejecting the objects with the test succeeding. |
Function | sync_do_select |
Filters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding. |
Function | sync_do_selectattr |
Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding. |
Function | sync_do_slice |
Slice an iterator and return a list of lists containing those items. Useful if you want to create a div containing three ul tags that represent columns: |
Function | sync_do_sum |
Returns the sum of a sequence of numbers plus the value of parameter 'start' (which defaults to 0). When the sequence is empty it returns start. |
Variable | _uri_scheme_re |
Undocumented |
Variable | _word_beginning_split_re |
Undocumented |
Variable | _word_re |
Undocumented |
Undocumented
Value |
|
Undocumented
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
func:t.Callable[ | Undocumented |
case_sensitive:bool | Undocumented |
attribute:t.Optional[ | Undocumented |
Returns | |
t.Union[ | Undocumented |
Undocumented
Parameters | |
attr:t.Optional[ | Undocumented |
Returns | |
t.List[ | Undocumented |
Get an attribute of an object. foo|attr("bar") works like foo.bar just that always an attribute is returned and items are not looked up.
See :ref:`Notes on subscriptions <notes-on-subscriptions>` for more details.
Parameters | |
environment:Environment | Undocumented |
obj:t.Any | Undocumented |
name:str | Undocumented |
Returns | |
t.Union[ | Undocumented |
A filter that batches items. It works pretty much like slice
just the other way round. It returns a list of lists with the
given number of items. If you provide a second parameter this
is used to fill up missing items. See this example:
<table> {%- for row in items|batch(3, ' ') %} <tr> {%- for column in row %} <td>{{ column }}</td> {%- endfor %} </tr> {%- endfor %} </table>
Parameters | |
value:t.Iterable[ | Undocumented |
linecount:int | Undocumented |
fill_with:t.Optional[ | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Parameters | |
s:str | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
value:str | Undocumented |
width:int | Undocumented |
Returns | |
str | Undocumented |
If the value is undefined it will return the passed default value, otherwise the value of the variable:
{{ my_variable|default('my_variable is not defined') }}
This will output the value of my_variable if the variable was
defined, otherwise 'my_variable is not defined'. If you want
to use default with variables that evaluate to false you have to
set the second parameter to true
:
{{ ''|default('the string was empty', true) }}
~jinja2.Environment
with
~jinja2.ChainableUndefined
to make the default
filter work
on nested elements and attributes that may contain undefined values
in the chain without getting an ~jinja2.UndefinedError
.Parameters | |
value:V | Undocumented |
default_value:V | Undocumented |
boolean:bool | Undocumented |
Returns | |
V | Undocumented |
Sort a dict and yield (key, value) pairs. Python dicts may not be in the order you want to display them in, so sort them first.
{% for key, value in mydict|dictsort %} sort the dict by key, case insensitive {% for key, value in mydict|dictsort(reverse=true) %} sort the dict by key, case insensitive, reverse order {% for key, value in mydict|dictsort(true) %} sort the dict by key, case sensitive {% for key, value in mydict|dictsort(false, 'value') %} sort the dict by value, case insensitive
Parameters | |
value:t.Mapping[ | Undocumented |
case_sensitive:bool | Undocumented |
by:te.Literal[ | Undocumented |
reverse:bool | Undocumented |
Returns | |
t.List[ | Undocumented |
True
the binary
prefixes are used (Mebi, Gibi).Parameters | |
value:t.Union[ | Undocumented |
binary:bool | Undocumented |
Returns | |
str | Undocumented |
Undocumented
Parameters | |
environment:Environment | Undocumented |
seq:t.Union[ | Undocumented |
Returns | |
t.Union[ | Undocumented |
Parameters | |
value:t.Any | Undocumented |
default:float | Undocumented |
Returns | |
float | Undocumented |
Parameters | |
value:t.Union[ | Undocumented |
Returns | |
Markup | Undocumented |
Apply the given values to a printf-style format string, like string % values.
{{ "%s, %s!"|format(greeting, name) }} Hello, World!
In most cases it should be more convenient and efficient to use the
% operator or str.format
.
{{ "%s, %s!" % (greeting, name) }} {{ "{}, {}!".format(greeting, name) }}
Parameters | |
value:str | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
str | Undocumented |
Undocumented
Parameters | |
environment:Environment | Undocumented |
value:t.Union[ | Undocumented |
attribute:t.Union[ | Undocumented |
default:t.Optional[ | Undocumented |
Returns | |
t.List[ | Undocumented |
Return a copy of the string with each line indented by 4 spaces. The first line and blank lines are not indented by default.
Changed in version 2.10: Blank lines are not indented by default.
Rename the indentfirst argument to first.
Parameters | |
s:str | Undocumented |
width:t.Union[ | Number of spaces, or a string, to indent by. |
first:bool | Don't skip indenting the first line. |
blank:bool | Don't skip indenting empty lines. |
Returns | |
str | Undocumented |
Parameters | |
value:t.Any | Undocumented |
default:int | Undocumented |
base:int | Undocumented |
Returns | |
int | Undocumented |
Undocumented
Parameters | |
eval_ctx:EvalContext | Undocumented |
value:t.Union[ | Undocumented |
d:str | Undocumented |
attribute:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Return the last item of a sequence.
Note: Does not work with generators. You may want to explicitly convert it to a list:
{{ data | selectattr('name', '==', 'Jinja') | list | last }}
Parameters | |
environment:Environment | Undocumented |
seq:t.Reversible[ | Undocumented |
Returns | |
t.Union[ | Undocumented |
Undocumented
Parameters | |
context:Context | Undocumented |
value:t.Union[ | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.AsyncIterable | Undocumented |
Parameters | |
value:str | Undocumented |
Returns | |
Markup | Undocumented |
safe
.Parameters | |
value:str | Undocumented |
Returns | |
str | Undocumented |
Return the largest item from the sequence.
{{ [1, 2, 3]|max }} -> 3
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
case_sensitive:bool | Treat upper and lower case strings as distinct. |
attribute:t.Optional[ | Get the object with the max value of this attribute. |
Returns | |
t.Union[ | Undocumented |
Return the smallest item from the sequence.
{{ [1, 2, 3]|min }} -> 1
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
case_sensitive:bool | Treat upper and lower case strings as distinct. |
attribute:t.Optional[ | Get the object with the min value of this attribute. |
Returns | |
t.Union[ | Undocumented |
Parameters | |
value:t.Any | Undocumented |
Returns | |
str | Undocumented |
Return a copy of the value with all occurrences of a substring replaced with a new one. The first argument is the substring that should be replaced, the second is the replacement string. If the optional third argument count is given, only the first count occurrences are replaced:
{{ "Hello World"|replace("Hello", "Goodbye") }} -> Goodbye World {{ "aaaaargh"|replace("a", "d'oh, ", 2) }} -> d'oh, d'oh, aaargh
Parameters | |
eval_ctx:EvalContext | Undocumented |
s:str | Undocumented |
old:str | Undocumented |
new:str | Undocumented |
count:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Round the number to a given precision. The first parameter specifies the precision (default is 0), the second the rounding method:
If you don't specify a method 'common' is used.
{{ 42.55|round }} -> 43.0 {{ 42.55|round(1, 'floor') }} -> 42.5
Note that even if rounded to 0 precision, a float is returned. If
you need a real integer, pipe it through int
:
{{ 42.55|round|int }} -> 43
Parameters | |
value:float | Undocumented |
precision:int | Undocumented |
method:te.Literal[ | Undocumented |
Returns | |
float | Undocumented |
Sort an iterable using Python's sorted
.
{% for city in cities|sort %} ... {% endfor %}
The sort is stable, it does not change the relative order of elements that compare equal. This makes it is possible to chain sorts on different attributes and ordering.
{% for user in users|sort(attribute="name") |sort(reverse=true, attribute="age") %} ... {% endfor %}
As a shortcut to chaining when the direction is the same for all attributes, pass a comma separate list of attributes.
{% for user users|sort(attribute="age,name") %} ... {% endfor %}
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
reverse:bool | Sort descending instead of ascending. |
case_sensitive:bool | When sorting strings, sort upper and lower case separately. |
attribute:t.Optional[ | When sorting objects or dicts, an attribute or key to sort by. Can use dot notation like "address.city". Can be a list of attributes like "age,name". |
Returns | |
t.List[ | Undocumented |
Parameters | |
value:t.Union[ | Undocumented |
Returns | |
str | Undocumented |
Undocumented
Parameters | |
environment:Environment | Undocumented |
iterable:t.Union[ | Undocumented |
attribute:t.Optional[ | Undocumented |
start:V | Undocumented |
Returns | |
V | Undocumented |
Parameters | |
s:str | Undocumented |
Returns | |
str | Undocumented |
Serialize an object to a string of JSON, and mark it safe to render in HTML. This filter is only for use in HTML documents.
The returned string is safe to render in HTML documents and <script> tags. The exception is in HTML attributes that are double quoted; either use single quotes or the |forceescape filter.
Parameters | |
eval_ctx:EvalContext | Undocumented |
value:t.Any | The object to serialize to JSON. |
indent:t.Optional[ | The indent parameter passed to dumps, for pretty-printing the value. |
Returns | |
Markup | Undocumented |
Parameters | |
value:str | Undocumented |
chars:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Return a truncated copy of the string. The length is specified with the first parameter which defaults to 255. If the second parameter is true the filter will cut the text at length. Otherwise it will discard the last word. If the text was in fact truncated it will append an ellipsis sign ("..."). If you want a different ellipsis sign than "..." you can specify it using the third parameter. Strings that only exceed the length by the tolerance margin given in the fourth parameter will not be truncated.
{{ "foo bar baz qux"|truncate(9) }} -> "foo..." {{ "foo bar baz qux"|truncate(9, True) }} -> "foo ba..." {{ "foo bar baz qux"|truncate(11) }} -> "foo bar baz qux" {{ "foo bar baz qux"|truncate(11, False, '...', 0) }} -> "foo bar..."
The default leeway on newer Jinja versions is 5 and was 0 before but can be reconfigured globally.
Parameters | |
env:Environment | Undocumented |
s:str | Undocumented |
length:int | Undocumented |
killwords:bool | Undocumented |
end:str | Undocumented |
leeway:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Returns a list of unique items from the given iterable.
{{ ['foo', 'bar', 'foobar', 'FooBar']|unique|list }} -> ['foo', 'bar', 'foobar']
The unique items are yielded in the same order as their first occurrence in the iterable passed to the filter.
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
case_sensitive:bool | Treat upper and lower case strings as distinct. |
attribute:t.Optional[ | Filter objects with unique values for this attribute. |
Returns | |
t.Iterator[ | Undocumented |
Quote data for use in a URL path or query using UTF-8.
Basic wrapper around urllib.parse.quote
when given a
string, or urllib.parse.urlencode
for a dict or iterable.
When given a string, "/" is not quoted. HTTP servers treat "/" and "%2F" equivalently in paths. If you need quoted slashes, use the |replace("/", "%2F") filter.
Parameters | |
value:t.Union[ | Data to quote. A string will be quoted directly. A dict or iterable of (key, value) pairs will be joined as a query string. |
Returns | |
str | Undocumented |
Convert URLs in text into clickable links.
This may not recognize links in some situations. Usually, a more comprehensive formatter, such as a Markdown library, is a better choice.
Works on http://, https://, www., mailto:, and email addresses. Links with trailing punctuation (periods, commas, closing parentheses) and leading punctuation (opening parentheses) are recognized excluding the punctuation. Email addresses that include header fields are not recognized (for example, mailto:address@example.com?cc=copy@example.com).
Parameters | |
eval_ctx:EvalContext | Undocumented |
value:str | Original text containing URLs to link. |
trim_url_limit:t.Optional[ | Shorten displayed URL values to this length. |
nofollow:bool | Add the rel=nofollow attribute to links. |
target:t.Optional[ | Add the target attribute to links. |
rel:t.Optional[ | Add the rel attribute to links. |
extra_schemes:t.Optional[ | Recognize URLs that start with these schemes in addition to the default behavior. Defaults to env.policies["urlize.extra_schemes"], which defaults to no extra schemes. |
Returns | |
str | Undocumented |
Parameters | |
s:str | Undocumented |
Returns | |
int | Undocumented |
Wrap a string to the given width. Existing newlines are treated as paragraphs to be wrapped separately.
Parameters | |
environment:Environment | Undocumented |
s:str | Original text to wrap. |
width:int | Maximum length of wrapped lines. |
break_long_words:bool | If a word is longer than width, break it across lines. |
wrapstring:t.Optional[ | String to join each wrapped line. Defaults to
Environment.newline_sequence . |
break_on_hyphens:bool | If a word contains hyphens, it may be split across lines. |
Returns | |
str | Undocumented |
Create an SGML/XML attribute string based on the items in a dict.
All values that are neither none
nor undefined
are automatically
escaped:
<ul{{ {'class': 'my_list', 'missing': none, 'id': 'list-%d'|format(variable)}|xmlattr }}> ... </ul>
Results in something like this:
<ul class="my_list" id="list-42"> ... </ul>
As you can see it automatically prepends a space in front of the item if the filter returned something unless the second parameter is false.
Parameters | |
eval_ctx:EvalContext | Undocumented |
d:t.Mapping[ | Undocumented |
autospace:bool | Undocumented |
Returns | |
str | Undocumented |
make_attrgetter
. Converts strings
to lowercase and returns other types as-is.Parameters | |
value:V | Undocumented |
Returns | |
V | Undocumented |
Parameters | |
environment:Environment | Undocumented |
attribute:t.Optional[ | Undocumented |
postprocess:t.Optional[ | Undocumented |
default:t.Optional[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Returns a callable that looks up the given comma separated attributes from a passed object with the rules of the environment. Dots are allowed to access attributes of each attribute. Integer parts in paths are looked up as integers.
The value returned by the returned callable is a list of extracted attribute values.
Examples of attribute: "attr1,attr2", "attr1.inner1.0,attr2.inner2.0", etc.
Parameters | |
environment:Environment | Undocumented |
attribute:t.Optional[ | Undocumented |
postprocess:t.Optional[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
context:Context | Undocumented |
args:t.Tuple | Undocumented |
kwargs:t.Dict[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
context:Context | Undocumented |
args:t.Tuple | Undocumented |
kwargs:t.Dict[ | Undocumented |
modfunc:t.Callable[ | Undocumented |
lookup_attr:bool | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Parameters | |
environment:Environment | Undocumented |
seq:t.Iterable[ | Undocumented |
Returns | |
t.Union[ | Undocumented |
Group a sequence of objects by an attribute using Python's
itertools.groupby
. The attribute can use dot notation for
nested access, like "address.city". Unlike Python's groupby,
the values are sorted first so only one group is returned for each
unique value.
For example, a list of User objects with a city attribute can be rendered in groups. In this example, grouper refers to the city value of the group.
<ul>{% for city, items in users|groupby("city") %} <li>{{ city }} <ul>{% for user in items %} <li>{{ user.name }} {% endfor %}</ul> </li> {% endfor %}</ul>
groupby yields namedtuples of (grouper, list), which can be used instead of the tuple unpacking above. grouper is the value of the attribute, and list is the items with that value.
<ul>{% for group in users|groupby("city") %} <li>{{ group.grouper }}: {{ group.list|join(", ") }} {% endfor %}</ul>
You can specify a default value to use if an object in the list does not have the given attribute.
<ul>{% for city, items in users|groupby("city", default="NY") %} <li>{{ city }}: {{ items|map(attribute="name")|join(", ") }}</li> {% endfor %}</ul>
Parameters | |
environment:Environment | Undocumented |
value:t.Iterable[ | Undocumented |
attribute:t.Union[ | Undocumented |
default:t.Optional[ | Undocumented |
Returns | |
t.List[ | Undocumented |
Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per default, you can define it with the optional parameter:
{{ [1, 2, 3]|join('|') }} -> 1|2|3 {{ [1, 2, 3]|join }} -> 123
It is also possible to join certain attributes of an object:
{{ users|join(', ', attribute='username') }}
attribute
parameter was added.Parameters | |
eval_ctx:EvalContext | Undocumented |
value:t.Iterable | Undocumented |
d:str | Undocumented |
attribute:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Applies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with lists of objects but you are really only interested in a certain value of it.
The basic usage is mapping on an attribute. Imagine you have a list of users but you are only interested in a list of usernames:
Users on this page: {{ users|map(attribute='username')|join(', ') }}
You can specify a default value to use if an object in the list does not have the given attribute.
{{ users|map(attribute="username", default="Anonymous")|join(", ") }}
Alternatively you can let it invoke a filter by passing the name of the filter and the arguments afterwards. A good example would be applying a text conversion filter on a sequence:
Users on this page: {{ titles|map('lower')|join(', ') }}
Similar to a generator comprehension such as:
(u.username for u in users) (getattr(u, "username", "Anonymous") for u in users) (do_lower(x) for x in titles)
Parameters | |
context:Context | Undocumented |
value:t.Iterable | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Iterable | Undocumented |
Filters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding.
If no test is specified, each object will be evaluated as a boolean.
Example usage:
{{ numbers|reject("odd") }}
Similar to a generator comprehension such as:
(n for n in numbers if not test_odd(n))
Parameters | |
context:Context | Undocumented |
value:t.Iterable[ | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Filters a sequence of objects by applying a test to the specified attribute of each object, and rejecting the objects with the test succeeding.
If no test is specified, the attribute's value will be evaluated as a boolean.
{{ users|rejectattr("is_active") }} {{ users|rejectattr("email", "none") }}
Similar to a generator comprehension such as:
(u for user in users if not user.is_active) (u for user in users if not test_none(user.email))
Parameters | |
context:Context | Undocumented |
value:t.Iterable[ | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Filters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding.
If no test is specified, each object will be evaluated as a boolean.
Example usage:
{{ numbers|select("odd") }} {{ numbers|select("odd") }} {{ numbers|select("divisibleby", 3) }} {{ numbers|select("lessthan", 42) }} {{ strings|select("equalto", "mystring") }}
Similar to a generator comprehension such as:
(n for n in numbers if test_odd(n)) (n for n in numbers if test_divisibleby(n, 3))
Parameters | |
context:Context | Undocumented |
value:t.Iterable[ | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding.
If no test is specified, the attribute's value will be evaluated as a boolean.
Example usage:
{{ users|selectattr("is_active") }} {{ users|selectattr("email", "none") }}
Similar to a generator comprehension such as:
(u for user in users if user.is_active) (u for user in users if test_none(user.email))
Parameters | |
context:Context | Undocumented |
value:t.Iterable[ | Undocumented |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Slice an iterator and return a list of lists containing those items. Useful if you want to create a div containing three ul tags that represent columns:
<div class="columnwrapper"> {%- for column in items|slice(3) %} <ul class="column-{{ loop.index }}"> {%- for item in column %} <li>{{ item }}</li> {%- endfor %} </ul> {%- endfor %} </div>
If you pass it a second argument it's used to fill missing values on the last iteration.
Parameters | |
value:t.Collection[ | Undocumented |
slices:int | Undocumented |
fill_with:t.Optional[ | Undocumented |
Returns | |
t.Iterator[ | Undocumented |
Returns the sum of a sequence of numbers plus the value of parameter 'start' (which defaults to 0). When the sequence is empty it returns start.
It is also possible to sum up only certain attributes:
Total: {{ items|sum(attribute='price') }}
attribute
parameter was added to allow suming up over
attributes. Also the start
parameter was moved on to the right.Parameters | |
environment:Environment | Undocumented |
iterable:t.Iterable[ | Undocumented |
attribute:t.Optional[ | Undocumented |
start:V | Undocumented |
Returns | |
V | Undocumented |