However, custom filter does not work when a context variable is invalid.
I attached sample project and you can see custom filter works when the
context variables is valid.
--
Ticket URL: <https://code.djangoproject.com/ticket/26606>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "invalid_string.zip" added.
sample project of custom filter with 'string if invalid' option
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
tested other filters like 'lower' but, it doesn't work with other filters
either.
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:1>
Comment (by timgraham):
I see this output. What output do you expect?
{{{
with filter
__FOO__
filter works with valid foo context
with tag
tag works with __FOO__
tag works with valid foo context
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:2>
Comment (by JosephDev):
if filter works with "string_if_invalid" option
the output should be
{{{
with filter
filter works with __FOO__
filter works with valid foo context
with tag
tag works with __FOO__
tag works with valid foo context
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:3>
Comment (by timgraham):
I don't see an advantage to running `string_if_valid` through template
filters -- they might transform the value to some other output which would
make it more difficult debug.
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:4>
Comment (by JosephDev):
"string_if_invalid" option works perfectly with context variables,
however, with request parameters, it makes redundant code.
Actually, I am supposed to get null string ("") when I don't need string
of "string_if_invalid" especially handle request parameters.
for example, to get null string (or to escape invalid string)
as is
{{{
<input name="foo" type="text" value="{% if request.GET.foo %}{{
request.GET.foo }}{% endif %}">
}}}
want to
{{{
<input name="foo" type="text" value="{{ request.GET.foo|or_null }}">
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:5>
Comment (by timgraham):
I'm having trouble understanding how your last comment relates to our
previous discussion.
Have you read the
"[https://docs.djangoproject.com/en/stable/ref/templates/api/#how-invalid-
variables-are-handled For debug purposes only]" note about
`string_if_invalid`? I get the sense that you may be trying to use
`string_if_invalid` for more than it's designed for.
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:6>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/26606#comment:7>