* status: new => closed
* ui_ux: => 0
* resolution: => wontfix
* easy: => 0
Comment:
This needs a stronger use-case justification. Many of the use-cases for
this are indications that the template should be re-structured, or an {%
include %} could be used instead. Capturing output like this is yet
another entirely different mental model for organizing and reusing
template code, and we already have at least two of those - we need strong
justification to add another to core (especially since it can work just
fine as an external snippet/library).
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by anonymous):
Does this justify as a general use-case?
{{{
{% capture as subject %}
{% if user = request.user %}My{% else %}{{ user.first_name }}'s{%
endif %}
{% endcapture %}
...
<div id="profile-photo">
My Photo
<img />
</div>
...
<div id="profile-friends">
<h3>{{ subjects }} Friends</h3>
List of friends...
</div>
<div id="profile-groups">
<h3>{{ subjects }} Groups</h3>
List of groups...
</div>
<div id="profile-friends">
<h3>{{ subjects }} Friends</h3>
List of friends...
</div>
...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:12>
* status: closed => reopened
* resolution: wontfix =>
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:13>
* owner: nobody => carljm
* status: reopened => new
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:14>
* stage: Design decision needed => Accepted
Comment:
I've changed my opinion on this; I do think there are cases where the
"capture" model is the appropriate one, and it ought to be built-in.
Particularly in cases like the above example, where a non-trivial block of
template should be repeated. Inheritance doesn't support this. Includes
could be used, but impose a significant performance penalty, both for
doing the include and because the repeated block has to be evaluated
multiple times. Otherwise you're reduced to a custom template tag.
Marking accepted, pending any argument from other core developers :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:15>
Comment (by aaugustin):
The use case doesn't seem that compelling to me — the logic calculating
"subject" /could/ be handled in the view.
That said, I don't have a strong opinion on this feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:16>
Comment (by carljm):
Replying to [comment:16 aaugustin]:
> The use case doesn't seem that compelling to me — the logic calculating
"subject" /could/ be handled in the view.
It could be, but it shouldn't be. Display logic in the view is ugly, just
like business logic in a template. And HTML in strings in the view is even
uglier.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:17>
* cc: charette.s@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:18>
Comment (by aaron@…):
Another use-case
cmsplugin_zinnia/templates/cmsplugin_zinnia/entry_detail.html:
{{{
{% load i18n placeholder_tags %}
{% for entry in entries %}
{% captureas content %}
{% render_placeholder entry.content_placeholder %}
{% endpatureas %}
{% with object=entry object_content=content continue_reading=1 %}
{% include "zinnia/_entry_detail.html" %}
{% endwith %}
{% empty %}
<p class="notice">{% trans "No entries yet." %}</p>
{% endfor %}
}}}
This is because rendering entry.content_placeholder generates sekizai_tags
that need to get picked up.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:19>
* cc: oss@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:20>
* cc: cmawebsite@… (added)
Comment:
This would make the template language turing-complete. I would use it.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:21>
* cc: loic84 (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:22>
Comment (by anonymous):
Any work on this ?
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:23>
* cc: cmawebsite@… (removed)
Comment:
Btw, if we did this, we would need to remove the line in philosophy docs
about intentionally not allowing assignment to variables.
https://docs.djangoproject.com/en/dev/misc/design-
philosophies/#don-t-invent-a-programming-language
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:24>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:25>
Comment (by prestontimmons):
Isn't the assignment to variables line kinda wrong anyway? Most template
tags accept the "as" argument, and the with tag also assigns variables,
albeit in a scoped manner.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:26>
Comment (by dracos):
Repeated includes hopefully no longer impose a significant performance
penalty since #23516, and blocktrans has a variable setting argument since
#21695, which was a reason given for this functionality (see e.g. similar
#14078).
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:27>
Comment (by collinanderson):
Fascinating. It sounds like #21695 actually solves this ticket, doesn't
it? The blocktrans tag should take care of any use case here, right? You
just need to do a null translation?
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:28>
* status: new => closed
* resolution: => wontfix
Comment:
Also #18651 enables optional assignments for `simple_tag()`.
I guess "wontfix" is the best resolution since we didn't really address
the issue directly as described in the original description.
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:29>
* cc: Carlton Gibson (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/6378#comment:30>