-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
How to use Django template variable on attr or set_data #116
Comments
It seems the only option is to use |
@bblanchon I have the same need. I am not sure if I understand your reply, because OP is already using I would need a way to add a string that contains a string and the value from a variable, much like OP. Specifically, to render the Both these solutions don't work: {{ field|attr:"aria-labelledby:{{ field.label}}Help" }}
{% render_field field|aria-labelledby:"{{ field.label}}Help" %}
# Needed to link the label to the help text
{% if field.help_text %}
<div id="{{ field.label }}Help" class="form-text">
{{ field.help_text | safe }}
</div>
{% endif %} |
I think what I meant to say is that @andreccorrea's only option was to do this: {% render_field field my-data=template_variable %} However, in your case @danielniccoli, you must append "help" to the string before passing it to {% with help_id=form.name.id_for_label|add:'_help' %}
{% render_field field aria-labelledby=help_id %}
<div id="{{ help_id }}" class="form-text">{{ field.help_text }}</div>
{% endwith %} |
{% with help_id=form.name.id_for_label|add:'_help' %}
^^^ That solved my problem! I wasn't aware I could use |
Is there any way to use a template variable as param for attr or set_data tags?
Something like:
{% render_field field|set_data:"my-data:{{ template_variable }}" %}
Doing the above passes literally the string '{{ template_variable }}' to my-data attribute and not the variable value as expected.
The text was updated successfully, but these errors were encountered: