has been updated to be more efficient and match more cases. URLs
without a scheme are linked as ``https://`` instead of ``http://``.
:issue:`522, 827, 1172`, :pr:`1195`
+- Filters that get attributes, such as ``map`` and ``groupby``, can
+ use a false or empty value as a default. :issue:`1331`
Version 2.11.3
for part in attribute:
item = environment.getitem(item, part)
- if default and isinstance(item, Undefined):
+ if default is not None and isinstance(item, Undefined):
item = default
if postprocess is not None:
tmpl = env.from_string(
'{{ users|map(attribute="lastname", default="smith")|join(", ") }}'
)
+ test_list = env.from_string(
+ '{{ users|map(attribute="lastname", default=["smith","x"])|join(", ") }}'
+ )
+ test_str = env.from_string(
+ '{{ users|map(attribute="lastname", default="")|join(", ") }}'
+ )
users = [
Fullname("john", "lennon"),
Fullname("jane", "edwards"),
Firstname("mike"),
]
assert tmpl.render(users=users) == "lennon, edwards, None, smith"
+ assert test_list.render(users=users) == "lennon, edwards, None, ['smith', 'x']"
+ assert test_str.render(users=users) == "lennon, edwards, None, "
def test_simple_select(self, env):
env = Environment()