allow simple_tag to set context?

已查看 1 次
跳至第一个未读帖子

Slowness Chen

未读,
2006年8月29日 02:49:172006/8/29
收件人 Django developers
simple_tag and inclusion_tag make writing simple template tags much more
convenient.
As the document says, "Another common type of template tag is the type that
displays
some data by rendering another template", e.g.

<ul>
{% for choice in choices %}
<li> {{ choice }} </li>
{% endfor %}
</ul>

But if there are many places in which you need to use inclusion_tag , it
gets annoying that you have to
extract all these *short and simple* snippets into separate template files.
If simple_tag can also
set context, that will be more convenient. Something like:
@register.simple_tag(sets_context=True)

Just some thoughts. any comments are welcome.

Malcolm Tredinnick

未读,
2006年8月29日 13:20:132006/8/29
收件人 django-d...@googlegroups.com

Seems reasonable to me. If you make a ticket for this and assign it to
me (mtredinnick in Trac), I'll handle this.

Cheers,
Malcolm


Slowness Chen

未读,
2006年8月29日 20:28:332006/8/29
收件人 Django developers
Done. Ticket #2619

Slowness Chen

未读,
2006年8月30日 09:15:072006/8/30
收件人 Django developers
I've attached my patch with the ticket. After patching both of the
following work:

# return a string , as before
@register.simple_tag
def func(...):
...
return 'a string'

# return a dict, items of the dict will be set to context
@register.simple_tag
def func(...):
...
return {'key' : value, ... }

回复全部
回复作者
转发
0 个新帖子