#6187 closed (worksforme)
FOR with filters, like slice, would be oh so nice
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | treborhudson@… | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
This would be handy to be able to do:
{% for item in item_list|slice:"1:" %}
...
{% endfor %}
I think it would require the for template tag to be pre-processed through whatever filter prior to iteration, correct?
The use case I was just working against was that I wanted to treat the first item in the list differently without having for loop logic. For example, something along these lines:
<h3>{{ item_list.0.title }}</h3>
<p>{{ item_list.0.body }}</p>
<h4>Other items</h4>
<ul>
{% for item in item_list|slice:"1:" %}
<li>{{ item.title }}</li>
{% endfor %}
</ul>
I realize maybe the example might be contrived, but for those filters that return a list (slice, make_list, others?) it also seems like a valid use that could come in handy.
Change History (2)
comment:1 by , 18 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 18 years ago
This appears to work for me if I wrap the queryset with a list() call. If I don't, the slice does nothing.
Doesn't it already do this? Does for me anyway.