i don't know for sure the exact answer of whether or not your include is cached, someone more intimate with core would know better than i...
but, i would recommend making your own template tag for doing this ( http://docs.djangoproject.com/en/dev/howto/custom-template-tags/) On Fri, May 21, 2010 at 1:29 PM, paul <[email protected]> wrote: > > > > On May 21, 12:46 am, Marcus Carlsson <[email protected]> > wrote: > > Does example.html print the data in `item` and if so, why not make the > > loop in example.html and just use include one time in your "main" > > template? > > > > Concerning your actual question. Even if it's cached it seems like bad > > practice to me so I would avoid using this method but without more info > > about what example.html holds it's hard to say. > > Let's say example.html outputs a html block showing some attributes of > item: > > {% for item in items %} > {% include "example.html" %} > {% endfor %} > > example.html: > <div> > {{ item.id }} {{ item.name }} > </div> > > > Obviously another solution is: > {% for item in items %} > <div> > {{ item.id }} {{ item.name }} > </div> > {% endfor %} > > > but in my case, it's useful for me to use example.html with other > templates. I thought about this some more and I'd suspect {% include > %} opens a file every time, as it's within a generic {% for %} loop, > unless {% include %} is structured to be able to reference a file it's > already opened. The reason I'm asking is because there would be a > performance penalty if the file has to be opened for every loop > iteration? > > > > > > On 21 May 12:40, paul wrote: > > > > > > > > > > > > > > > > > sorry -- I made a mistake -- I meant include instead of extends :-p > > > > > {% for item in items %} > > > {% include "example.html" %} > > > {% endfor %} > > > > > does example.html get opened for every iteration of the loop, or just > > > at the first iteration, and then perhaps cached? > > > > > On May 21, 12:36 am, paul <[email protected]> wrote: > > > > hi -- given this example template: > > > > > > {% for item in items %} > > > > {% extends "example.html" %} > > > > {% endfor %} > > > > > > When this block is evaluated during template rendering, does the file > > > > "example.html" get opened for every iteration of the loop, or might > > > > the contents of "example.html" get cached the first time it's opened? > > > > > > -- > > > > You received this message because you are subscribed to the Google > Groups "Django users" group. > > > > To post to this group, send email to [email protected]. > > > > To unsubscribe from this group, send email to > [email protected]<django-users%[email protected]> > . > > > > For more options, visit this group athttp:// > groups.google.com/group/django-users?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups "Django users" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > [email protected]<django-users%[email protected]> > . > > > For more options, visit this group athttp:// > groups.google.com/group/django-users?hl=en. > > > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > [email protected]<django-users%[email protected]> > . > > For more options, visit this group athttp:// > groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<django-users%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

