Re: is it possible to make the |safe template filter conditional on content
You can certainly write a custom filter. And if you do that, you can divvy up your value into footnote links and other, and escape the other parts yourself, returning the result as a safe string.
On Thu, Oct 3, 2013 at 2:55 AM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
I made a custom template filter (ref_href) which converts numbered references (like [1], [2] etc) into footnote hyperlinks. It works but requires the |safe filter which is dangerous.
To be actually safe I want to *only* use the |safe filter when the data contains a numbered reference. Which I cannot do if it is permanently in the template. In other words, I want to remove the |safe filter from the template and incorporate it into my custom filter which checks that we have an integer between the square brackets before doing its work.
Just thinking about it now, I suppose I could put a conditional in the template ...
{% if "[" in value %}
{{ value | ref_href | safe }}
{% else %}
{{ value }}
{% endif %}
... but that's a lot of typing over dozens of templates. And it isn't good enough.
Thanks for any secrets
Mike
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/524D14D9.5090605%40dewhirst.com.au.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB%2BAj0uMUVFmHGY%3DYckq_e03ve1WhKG29ruCUWRU2zaVuFsN2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home