﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36186	forloop should have an accessor for the total count of the loop	Jonathan Ströbele	Jonathan Ströbele	"The `forloop` has no way for accessing the total loop iteration count, though the [https://github.com/django/django/blob/47c837a1ff96ef1b10b44477a7a9f72283d12e83/django/template/defaulttags.py#L199C13-L199C14 length of the values being iterated] is already known on the logic for building up the `forloop` variable.

I propose to expose this count on the `forloop` variable, i.e. like: `forloop.total`. I think it can be helpful to have this information available inside a loop if needed (this also the case for example in the [https://laravel.com/docs/11.x/blade#the-loop-variable Laravel/Blade loop variable]):

{{{
{% for val in values %}
  {{ forloop.total }}
{% endfor %}
}}}

I prepared a patch here and can send it of as a PR if it's okay: https://github.com/stroebjo/django/commit/0a6233bcd9f2356a2b7b646ad4448ee313dc4d43 "	New feature	closed	Template system	5.1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
