class documentation

class LoopContext: (source)

Known subclasses: jinja2.runtime.AsyncLoopContext

View In Hierarchy

A wrapper iterable for dynamic ``for`` loops, with information about the loop and iteration.

Method __call__ When iterating over nested data, render the body of the loop recursively with the given inner iterable data.
Method __init__ :param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive...
Method __iter__ Undocumented
Method __len__ Undocumented
Method __next__ Undocumented
Method __repr__ Undocumented
Method changed Return ``True`` if previously called with a different value (including when called for the first time).
Method cycle Return a value from the given args, cycling through based on the current :attr:`index0`.
Class Variable index0 Undocumented
Instance Variable depth0 Undocumented
Property depth How many levels deep a recursive loop currently is, starting at 1.
Property first Whether this is the first iteration of the loop.
Property index Current iteration of the loop, starting at 1.
Property last Whether this is the last iteration of the loop.
Property length Length of the iterable.
Property nextitem The item in the next iteration. Undefined during the last iteration.
Property previtem The item in the previous iteration. Undefined during the first iteration.
Property revindex Number of iterations from the end of the loop, ending at 1.
Property revindex0 Number of iterations from the end of the loop, ending at 0.
Static Method _to_iterator Undocumented
Method _peek_next Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called.
Class Variable _length Undocumented
Instance Variable _after Undocumented
Instance Variable _before Undocumented
Instance Variable _current Undocumented
Instance Variable _iterable Undocumented
Instance Variable _iterator Undocumented
Instance Variable _last_changed_value Undocumented
Instance Variable _recurse Undocumented
Instance Variable _undefined Undocumented
@internalcode
def __call__(self, iterable): (source)

When iterating over nested data, render the body of the loop recursively with the given inner iterable data. The loop must have the ``recursive`` marker for this to work.

Parameters
iterable:t.Iterable[V]Undocumented
Returns
strUndocumented
def __init__(self, iterable, undefined, recurse=None, depth0=0): (source)

:param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive. :param depth0: Incremented when looping recursively.

Parameters
iterable:t.Iterable[V]Undocumented
undefined:t.Type[Undefined]Undocumented
recurse:t.Optional[LoopRenderFunc]Undocumented
depth0:intUndocumented
def __iter__(self): (source)

Undocumented

Returns
LoopContextUndocumented
def __len__(self): (source)

Undocumented

Returns
intUndocumented
def __next__(self): (source)

Undocumented

Returns
t.Tuple[t.Any, LoopContext]Undocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def changed(self, *value): (source)

Return ``True`` if previously called with a different value (including when called for the first time). :param value: One or more values to compare to the last call.

Parameters
*value:t.AnyUndocumented
Returns
boolUndocumented
def cycle(self, *args): (source)

Return a value from the given args, cycling through based on the current :attr:`index0`. :param args: One or more values to cycle through.

Parameters
*args:VUndocumented
Returns
VUndocumented
index0: int = (source)

Undocumented

depth0 = (source)

Undocumented

How many levels deep a recursive loop currently is, starting at 1.

Whether this is the first iteration of the loop.

Current iteration of the loop, starting at 1.

Whether this is the last iteration of the loop. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`groupby` filter avoids that issue.

Length of the iterable. If the iterable is a generator or otherwise does not have a size, it is eagerly evaluated to get a size.

The item in the next iteration. Undefined during the last iteration. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`jinja-filters.groupby` filter avoids that issue.

The item in the previous iteration. Undefined during the first iteration.

@property
revindex: int = (source)

Number of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`.

@property
revindex0: int = (source)

Number of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`.

@staticmethod
def _to_iterator(iterable): (source)

Undocumented

Parameters
iterable:t.Iterable[V]Undocumented
Returns
t.Iterator[V]Undocumented
def _peek_next(self): (source)

Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called.

Returns
t.AnyUndocumented

Undocumented

_after = (source)

Undocumented

_before = (source)

Undocumented

_current = (source)

Undocumented

_iterable = (source)

Undocumented

_iterator = (source)

Undocumented

_last_changed_value = (source)

Undocumented

_recurse = (source)

Undocumented

_undefined = (source)

Undocumented