Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'loop' is undefined #29

Open
dAnjou opened this issue May 1, 2024 · 2 comments
Open

'loop' is undefined #29

dAnjou opened this issue May 1, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@dAnjou
Copy link

dAnjou commented May 1, 2024

Hi,

I'm migrating a traditional Flask+Jinja2 app to one with HTMX. Similar to #23, I'm using a block inside a loop.

I'm also using the special loop.index variable, which is when I'm getting: jinja2.exceptions.UndefinedError: 'loop' is undefined.

I know I can get around that by simply wrapping my iterable into list(enumerate(...)), but it'd probably make a smoother experience if loop was available.

Not sure if that's even possible. If not, it should probably be documented as a caveat.

🙏

@sponsfreixes sponsfreixes added the enhancement New feature or request label May 2, 2024
@sponsfreixes
Copy link
Owner

Good point about at least adding that to the docs!

@gconklin
Copy link
Contributor

My hacky workaround for this was something like:

class FakeLoop:
    last = True
return render_block(file, fragment, loop=FakeLoop())

but I didn't have anything complex and only needed that one attribute.

@sponsfreixes sponsfreixes added the documentation Improvements or additions to documentation label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants