On 13 October 2011 15:30, LeeS <[email protected]> wrote:
> Not sure if this is still an ongoing discussion, but I prefer to write
> all new tags with a simple syntax that matches Python. There's no
> real advantage in defining a unique, custom syntax for a template
> tag.
>
> All HTML authors are already familiar with Python's kwargs syntax,
> since it exactly matches how HTML tags and attributes themselves
> work. There's no great leap of difficulty going from:
>
> <div class="something" style="something">
> to
> {% tag foo="something" bar="something" %}
>
> Allowing for arbitrary custom syntax makes tags harder for HTML
> coders, since they have to remember these special custom syntaxes
> which they're not used to.
Note that since the recent r16908 [1], this is easily achievable with
simple_tag, include_tag or assignment_tag, which now replicate the Python
way of handling *args and **kwargs.
The only thing that's still not possible with these is to define a complex
or custom syntax, e.g.: {% mytag with myvar using "blah" %}
However, if one is OK to not have a custom syntax, then the following is now
dead-easy:
{% mytag with=myvar using="blah" %}
@simple_tag
def mytag(with=None, using="Yadi Yada"):
...
Cheers,
Julien
[1] https://code.djangoproject.com/changeset/16908
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.