By the way, this could also be implemented using just files. The way {%
include %} works for macros. If that's preferred. That becomes:
{% decorate "my_special_for.html" data %}
<li>{{ i.value }}</li>
{% enddecorate %}
Le lundi 3 juin 2013 13:38:29 UTC+2, Jonathan Slenders a écrit :
>
> Hi all. In the past, I once proposed a decorate template tag, but it was
> disapproved back then.
> This would be another solution, to make the template language a lot more
> powerful.
>
> 1. First you define a decorator, for the behaviour you'd like to have. The
> "data" parameter indicates the receiving parameters.
>
> {% define my_special_for "data" %}
> {% if data %}
> <ul>
> {% for i in data %}
> {% placeholder %}
> {% endfor %}
> </ul>
> {% else %}
> nothing found...
> {% endif %}
> {% enddefine %}
>
>
> This definition can be used as follows:
>
> {% decorate my_special_for data %}
> <li>{{ i.value }}</li>
> {% enddecorate %}
>
>
> Not sure about the namings, but personally, I'm very convinced about this
> appoach. There shouldn't be too much logic in the template tags itself.
>
> Another nice thing is that the <ul> and </ul> tags happen to be in exact
> the same scope which increases readability and the posibilities for
> automatic validation.
>
> An extended version would create a second {% placeholder %} block for the
> "nothing found..." part.
>
> If this is an acceptable appoach, I'm willing to contribute this to Django
> core, and write unit-tests and such.
>
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.