Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add {% attrs %} tag to generate attributes without field #151

Open
christophehenry opened this issue Nov 18, 2024 · 1 comment
Open

Add {% attrs %} tag to generate attributes without field #151

christophehenry opened this issue Nov 18, 2024 · 1 comment

Comments

@christophehenry
Copy link

The attr filter is nice to append HTML attributes to form fields but it would be nicer being able to also use it without fields like this:

{% attr "data-test-thing:test-value" as attr_dict %}
<section {{ attr_dict }}>
…
</section>

I couldn't find this feature request in the open tickets. Please excuse if this is a duplicate.

@maximbelyayev
Copy link

maximbelyayev commented Dec 21, 2024

+1. Would be nice if we could {% render_field field attr_dict=attr_dict %}, if attr_dict is provided in context.

Especially for working with django-components where keys in context dict can change, reduces the annoyance to have a million nested if attr, render_fileld, and endif statements and ensure you have every permutation like:

{% if attr %}
    {% if attr1 %}
        {% if attr2 %}
             {% render_field field attr=attr attr1=attr1 attr2=attr2 %}
        {% else %}
             {% render_field field attr=attr attr1=attr1 %}
        {% endif %}
    {% elif attr2 %}
        {% render_field field attr=attr attr2=attr2 %}
    {% else %}
        {% render_field field attr=attr %}
{% elif attr1 %}
    {% if attr2 %}
        {% render_field field attr1=attr1 attr2=attr2 %}
    {% else %}
        {% render_field field attr1=attr1 %}
{% elif attr2 %}
    {% render_field field attr2=attr2 %}
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants