jeudi 1 janvier 2015

Django: custom tag and tag evaluation in template


Vote count:

0




I wrote a custom tag named addattrs that allow me add HTML attributes easily.


I uses it that way:



<div>
<label>Last name</label>
{{ form.last_name|addattrs:"class=blue-form&placeholder=Please enter your name" }}
</div>


It works well. But now, I'd like to add the value attribute to HTML:



<div>
<label>Last name</label>
<!-- last_name is availaible from the current context -->
{{ form.last_name|addattrs:"class=blue-form&value=last_name" }}
</div>


The problem is last_nameis not evaluated and wrote as is in my form. How to force last_name to be evaluated? I tried a {% with last_name as myvariable %} block, but the result is exactly the same.


Thanks.



asked 1 min ago

David W.

1,183






Django: custom tag and tag evaluation in template

Aucun commentaire:

Enregistrer un commentaire