RE: [Zope] DTML Document Properties strangeness
Hi there,
I've posted about this before but didn't get a satisfactory answer yet. I'm using an external method with a DTML Document, and inside that external method I want to look at the properties of the DTML Document. I keep having problems with it so I reduced the problem to the following. I have this external method:
def getPropertyIds(self): return self.propertyIds()
Inside a DTML Document I have this:
<!--#var standard_html_header--> <p><!--#var "getPropertyIds()"--></p> <p><!--#var "propertyIds()"--></p> <!--#var standard_html_footer-->
I would expect these two to give the same list of property ids, but instead the external method returns the list of properties in the *folder*, not in the document (like <!--#var "propertyIds()"--> does).
Am I doing something wrong, or is this a bug? A related question: is there a way to check if a property id (acquired from the folder *or* defined locally in the DTML Document) exists or not (and get at its contents), from within an external method? hasProperty is not working well either...
Martijn, Remember that DTML Documents behave a little differently than DTML Methods, External Methods and other "method"-like objects. The "self" in your "getPropertyIds" external method is going to be the _folder_, not the DTML Document. In a DTML Document, the implicit "self" namespace is the DTMLDocument itself, but this does extend to any method-like objects called from the DTML Document - they will continue to act as methods of their containers (and _not_ like methods of the DTML Document). One thing you could do to accomplish what you are trying to do is to extend your getPropertyIds() method to accept an argument: def getPropertyIds(self, obj): return obj.propertyIds() <!--#var "getPropertyIds(this())"--> Hope this helps! Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
Brian Lloyd wrote: [snip]
The "self" in your "getPropertyIds" external method is going to be the _folder_, not the DTML Document. In a DTML Document, the implicit "self" namespace is the DTMLDocument itself, but this does extend to any method-like objects called from the DTML Document - they will continue to act as methods of their containers (and _not_ like methods of the DTML Document).
The confusing thing is that a DTML Document is according to the documentation: """DTML Document objects are DocumentTemplate.HTML objects that act as methods whose self is the DTML Document itself.""" I thought that this would mean the 'self' argument passed to an external method would be the 'self' of the DTML document, not the containing folder.
One thing you could do to accomplish what you are trying to do is to extend your getPropertyIds() method to accept an argument:
def getPropertyIds(self, obj): return obj.propertyIds()
<!--#var "getPropertyIds(this())"-->
Yes, I suppose I'll have to go for that, but it takes away some of the simplicity of my External Method. It pulls text from properties and renders them in a page as structured text. If you're logged in as Manager, you get an extra hyperlink with the text. If you click on it, you get a simple web page with a textarea box on it. You can type in new structured text, press okay, and voila, the text on the page is changed. The DTML that accomplishes all this (along with the supporting editor page and the external method) is just: <!--#var "editable('some_property')"--> Now it'd have to be: <!--#var "editable(this(), 'some_property')"--> More typing! :) Anyway, it'll have to do -- this is mainly a hack for demo purposes. Later on (this summer!) we're planning to build simple authoring tools on top of your membership system to be (at least I hope -- I don't know anything about the membership system so I don't know if it'll suit our needs; any chance some info is leaking out soon?). The idea is that the website here can be kept up to date by allowing maintainers (each page has a list of maintainers) to edit their web pages from the web in a very _very_ simple way (no HTML knowledge required). If all these plans go through you're bound to hear more on this later. :)
Hope this helps!
Thanks, it does. I think I saw 'this()' before but couldn't find how to do that the other day when I was looking for it. Regards, Martijn
participants (2)
-
Brian Lloyd -
Martijn Faassen