On Wed, 2008-09-24 at 02:36 -0700, bruno desthuilliers wrote: > Hi all > > I don't know wether it's me doing something wrong, or if it's a normal > limitation of Django's templates, or else, but anyway, here's the > problem: > > I have a custom tag that sets a variable in the context (the usual > way, ie 'context[self.varname] = something'). This is not my first > custom tag, nor the first context-updating one, so I don't think > there's anything wrong so far. > > Now I have this template that extends a base template - I didn't wrote > personnaly FWIW - that has quite a lot of nested blocks definitions - > the idea being to let you override either a whole block or just part > of it. Might be a good idea or not, don't know (as far as I'm > concerned, I wouldn't have done such a thing, but that's another > question...). The doc doesn't mention nesting blocks, but well, it > seems to work fine... *as long* as you only access vars defined in the > view itself *or* have the call to the context-setting tag in the same > block where you access the var. That is : when calling a context- > setting tag anywhere else (top level, prior block at the same level > etc), the var is just not there.
I may not be completely understanding the problem you're explaining -- a short example from you may help illustrate the exact difficulty. However, it looks like what you're seeing is expected behaviour: whenever a block ends (when an "endblock" marker is encountered), anything set inside that block in the context is popped off the stack and removed. The idea is that the Context instance is a stack of values and each new nesting level introduces a new entry on the stack. When you go to look up variable "foo", it finds the first occurence of "foo" in the stack -- maybe in the current block, or in one of the ancestor blocks (all the way back to the top-level template). When a block finished, we remove all the context for that block so as not to pollute any other processing. It sounds like you're saying that an outer block cannot access an inner block's context and that would be correct, since the context for the inner block is only available inside that block (and to any children of that block, not to any ancestors). Again, if I haven't understood what you are describing, please write a short example of two templates demonstrating what you are trying to achieve. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

