Multiline tags (again)

10 views
Skip to first unread message

Axel Haustant

unread,
Oct 1, 2013, 7:01:31 AM10/1/13
to django...@googlegroups.com
Hi everyone!

I'm sorry to put this subject on the table again, but I maybe have some new arguments.

The main point for not adding multiline tags support is to "force" developers to keep logic outside templates and keep templates as simple as possible.
I agree on this point and the Django templating system is doing a great job.

But sometimes (many times in fact), this is required not for logic.
I have at least one main example: the {% blocktrans %} template tag with parameters.
In this case there is no logic at all, but I find myself writing this kind of translation a lot of time:

{% blocktrans with from=some_object.from_date|date:"SHORT_DATE_FORMAT" to=some_object.to_date|date:"SHORT_DATE_FORMAT" %}
{{ from }} to {{ to }}
{% endblocktrans %}

If I don't want to include line returns, I must write:
{% blocktrans with from=some_object.from_date|date:"SHORT_DATE_FORMAT" to=some_object.to_date|date:"SHORT_DATE_FORMAT" %}{{ from }} to {{ to }}{% endblocktrans %}

In this example, I only have two dates and names are relatively shorts and the line is already huge to me.

I can't stop thinking this would be easier to write and understand:

{% blocktrans with
    from=temporal_coverage.from|date:"SHORT_DATE_FORMAT"
    to=temporal_coverage.to|date:"SHORT_DATE_FORMAT"
%}
{{ from }} to {{ to }}
{% endblocktrans %}

or even better to remove line returns:

{% blocktrans with
    from=temporal_coverage.from|date:"SHORT_DATE_FORMAT"
    to=temporal_coverage.to|date:"SHORT_DATE_FORMAT"
%}{{ from }} to {{ to }}{% endblocktrans %}

The same applies to {% with %} template tag because tend to think this:

{% with
     some_var=some_object.some_nested.some_attr
     another_var=another_object.some_nested.some_attr
%}

is simpler to write and read than:

{% with some_var=some_object.some_nested.some_attr another_var=another_object.some_nested.some_attr %}

Having to horizontally scroll my logicless templates every times is a real pain in the ass!!

The Django slogan is "The Web framework for perfectionists with deadlines" and as a perfectionist with deadline, I want write clean code without having to waste time writing a custom template tag for each specific case.
So if the point beside "keeping logic outside templates" is to keep template simples, I think there should be multine template tags support, at least tags supporting args and kwargs.
If I follow the current reasoning (you don't want people using args and kwargs too much) then you should simply remove them but it will be a sad move.

Best,

--
Axel H.
Reply all
Reply to author
Forward
0 new messages