DTMLFile, the mysterious animal
Can somebody explain to me what really happens when I have a method in my product like DTMLFile('www/main.dtml', globals(), filter='Image'). My problem is that I want to modify the stock main.dtml in order to show only a subset of contained objects, so I change the line <dtml-in objectItems ...> to <dtml-in "objectItems(filter)" ...> and now I get a TypeError, "object of type 'list' is not callable" I know that something like OrderedFolder etc. might do what I want, but I'm curious about what really happens here. cheers, oliver
DTMLFile is a class, and is generally instantiated at import time. Passing arguments to the class constructor (filter='Image') doesn't affect the execution of the instance itself (the dtml code). To pass arguments to the instance, you do so when you actually call it. If its being called from the web (a likely thing), then you can pass arguments on the query string (?filter=Image). If you cannot do this, then you must wrap the dtml file call in another method that supplies the arguments, something like: main_dtml = DTMLFile('www/main.dtml', globals()) def main(self, context, REQUEST, **kw): kw['filter'] = 'Image' return self.main_dtml(context, REQUEST, **kw) hth, -Casey On Monday 19 August 2002 01:19 pm, Oliver Bleutgen wrote:
Can somebody explain to me what really happens when I have a method in my product like DTMLFile('www/main.dtml', globals(), filter='Image').
My problem is that I want to modify the stock main.dtml in order to show only a subset of contained objects, so I change the line <dtml-in objectItems ...> to <dtml-in "objectItems(filter)" ...>
and now I get a TypeError, "object of type 'list' is not callable"
I know that something like OrderedFolder etc. might do what I want, but I'm curious about what really happens here.
cheers, oliver
Casey Duncan wrote:
DTMLFile is a class, and is generally instantiated at import time. Passing arguments to the class constructor (filter='Image') doesn't affect the execution of the instance itself (the dtml code).
To pass arguments to the instance, you do so when you actually call it. If its being called from the web (a likely thing), then you can pass arguments on the query string (?filter=Image). If you cannot do this, then you must wrap the dtml file call in another method that supplies the arguments, something like:
main_dtml = DTMLFile('www/main.dtml', globals())
def main(self, context, REQUEST, **kw): kw['filter'] = 'Image' return self.main_dtml(context, REQUEST, **kw)
hth,
-Casey
Many thanks Casey, I see it was a quite dumb mistake, what confused me was that apparently I managed to create a situation where objectItems wasn't callable anymore (as the error told me). Anyway, now it works, thanks again. cheers, oliver
participants (2)
-
Casey Duncan -
Oliver Bleutgen