The code `e.generalov` gave has been valid since Django 2.3: <https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include>
For more complicated context, you can also write an inclusion tag < https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags> and use that to render the inner template. On Tuesday, September 4, 2012 6:21:47 PM UTC-4, Ivan Kirigin wrote: > > I find myself writing things like this a lot in django templates > > {% for e in some_list %} > {% with e as element %} > {% include "single_element.html" %} > {% endwith %} > {% enfor %} > > This would be in a template which shows a lists of elements, with another > template that renders a single one. The template single_element.html uses > element locally. I find this encapsulates my templates well, especially > in making single_element.html far more reusable. > > I've been doing this for a while and wanted to know if there is a better > way I just don't know about. Also, I don't know the performance > implications of so many with/include calls. This list could be very long > (100s or 1000s). > > Thanks! > Ivan Kirigin > http://kirigin.com > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/aeoIyYajiZcJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.