silviogutierrez / reactivated

https://www.reactivated.io
MIT License
669 stars 20 forks source link

Naming a template context key "items" does not work #380

Open dnet opened 3 weeks ago

dnet commented 3 weeks ago

Thanks for the interesting project, I have started to experiment with it for an existing internal project. For one of the templates, I named a context key items like this:

@template
class MyTemplate(NamedTuple):
    foo: Bar
    items: List[Qux]

And then in the client code:

<ul>
        {props.objects.map((item) => <li>{item.baz}</li>)}
</ul>

Running manage.py runserver completed without errors, however the page loaded while showing two "empty" <li> items, even though I supplied more than that. If I renamed items to objects the problem went away, so it is probably a naming clash with template.items:

https://github.com/silviogutierrez/reactivated/blob/19e3d99d057ba721c5f4d1aee50d3a6d2fa8105d/reactivated/templates.py#L79

I guess it would be nicer to warn users

silviogutierrez commented 3 weeks ago

Nice catch, will keep this open to address it. Rewriting the whole template system soon.