django-widget-tweaks icon indicating copy to clipboard operation
django-widget-tweaks copied to clipboard

TemplateSyntaxError: Could not parse the remainder

Open matiaschn opened this issue 10 months ago • 1 comments

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 ? ''

matiaschn avatar Jan 19 '25 00:01 matiaschn

You could try using the pipe syntax, kind of like issue #85, but ideally there would be a better way

TeaDrinkingProgrammer avatar Feb 11 '25 16:02 TeaDrinkingProgrammer

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'
            "

danjac avatar Sep 14 '25 09:09 danjac