django-widget-tweaks
django-widget-tweaks copied to clipboard
TemplateSyntaxError: Could not parse the remainder
I'm trying to pass x-bind attribute from alpinejs using ternary operator but I get TemplateSyntaxError:
{% render_field form.password x-bind::type="show ? 'text' : 'password'" %}
Error:
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '"show ? '' from '"show ? ''
You could try using the pipe syntax, kind of like issue #85, but ideally there would be a better way
The workaround I found for this same issue was to use x-ref e.g.
{% render_field field x-ref="password" %}
x-on:click="
show = !show;
$refs.password.type = show ? 'text' : 'password'
"