On 14 Jul 2006, at 03:05, Malcolm Tredinnick wrote:

> Is there any alternative to creating an escaped_unordered_list tag?  
> (Any
> better name for this tag? It's too long)

Yes. Implementing the auto escape proposal.

> [Note: useful responses to this question do not include "auto-escaping
> would be nice". That is not the issue here and it gets tiring reading
> it.]

I would argue that it is the issue here - more specifically, the  
current auto_escape proposal is designed to tackle this exact  
problem, among others.

http://code.djangoproject.com/wiki/AutoEscaping

The solution lies with the way the proposal flags strings as escaped  
or unescaped. The unordered_list tag would escape items passed in to  
it based on the current state of the auto_escape flag combined with  
whether or not the item was flagged as already having been escaped.

Output an unordered list with each item escaped:
{{ list_of_unsafe_strings|unordered_list }}  - assumes default for  
the current template is autoescape on

Output an ordered list where each item can contain HTML:
{% autoescape off %}
{{ list_of_unsafe_strings|unordered_list }}
{% endautoescape %}

Alternatively, if the fact that the items contain safe HTML is known  
by the view:

c = Context({
   'items': map(escapedstr, items)
})

And in the template:

{{ items|unordered_list }}

Because the items have all been flagged as escaped, the auto escaping  
mechanism will skip them and the safe HTML will be rendered as required.

unordered_list was one of the use cases I was thinking about when I  
drew up the proposal. I should probably update the wiki page to  
reflect that.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to