Re: [Zope] Re: newbie question: make reference to a 'foreign' variable
Hi, i have tried this too, but it gave me another error message: AttributeError <dtml-var "PARENTS[-1].GuestBook.addEntryAction"> what am i doing wrong? --- "Michael R. Bernstein" <webmaven@lvcm.com> schrieb: > On Sat, 2003-02-08 at 08:32, Sungmook Kim wrote:
Hi,
sorry, I meant the folder A is not a subfolder of B but of some other folder X which is also a root folder itself.
-B | --variable(dtml method) -X | -A | --dtml-document(here, i want to make a reference to the variable in folder B)
Ok, you seem to be using 'root folder' to mean 'a folder in the root folder'. There is onmly one root folder ('/').
So your diagram should be:
/ +-B | +-variable | +-X +-A +-dtml-document
So, the simple way to solve this is to start from the root folder and work your way down:
<dtml-with "PARENTS[-1]"> <dtml-with B> <dtml-var variable> </dtml-with> </dtml-with>
"PARENTS[-1]" always get's you the root folder in Zope. This code will always get you variable-of-B-of-root, no matter where in the tree you call it from.
-- Michael R. Bernstein <webmaven@lvcm.com>
__________________________________________________________________ Gesendet von Yahoo! Mail - http://mail.yahoo.de Bis zu 100 MB Speicher bei http://premiummail.yahoo.de
On Sat, 2003-02-08 at 10:42, Sungmook Kim wrote:
Hi,
i have tried this too, but it gave me another error message: AttributeError
<dtml-var "PARENTS[-1].GuestBook.addEntryAction">
what am i doing wrong?
Ah. addEntryAction is a method, not a property. When calling a method in Python (and this is a Python expression, BTW), you need to call it like this: <dtml-var "PARENTS[-1].GuestBook.addEntryAction()"> Depending on the method in question, you may need to supply arguments as well: <dtml-var "PARENTS[-1].GuestBook.addEntryAction(arg1='value1', arg2='value2')"> I'd like to point out that it is generally a *very bad idea* to be using DTML for application logic like this. You would be better off switching to a combination of Python Script objects and DTML, or Python Scripts and ZPT. -- Michael R. Bernstein <webmaven@lvcm.com>
yep, it's a method. but within the folder guestbook, i call this method as <dtml-var addEntryAction> and it works. whereas the addEntryAction calls <dtml-call expr="addEntry(arg1, arg2,...)"> i thought this should work in another folder X too by writing <dtml-var "PARENTS[-1].GuestBook.addEntry(arg1,arg2,...)"> should it not? --- "Michael R. Bernstein" <webmaven@lvcm.com> schrieb: > On Sat, 2003-02-08 at 10:42, Sungmook Kim wrote:
Hi,
i have tried this too, but it gave me another error message: AttributeError
<dtml-var "PARENTS[-1].GuestBook.addEntryAction">
what am i doing wrong?
Ah. addEntryAction is a method, not a property. When calling a method in Python (and this is a Python expression, BTW), you need to call it like this:
<dtml-var "PARENTS[-1].GuestBook.addEntryAction()">
Depending on the method in question, you may need to supply arguments as well:
<dtml-var "PARENTS[-1].GuestBook.addEntryAction(arg1='value1', arg2='value2')">
I'd like to point out that it is generally a *very bad idea* to be using DTML for application logic like this. You would be better off switching to a combination of Python Script objects and DTML, or Python Scripts and ZPT.
-- Michael R. Bernstein <webmaven@lvcm.com>
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
__________________________________________________________________ Gesendet von Yahoo! Mail - http://mail.yahoo.de Bis zu 100 MB Speicher bei http://premiummail.yahoo.de
On Sat, 2003-02-08 at 15:19, Sungmook Kim wrote:
yep, it's a method. but within the folder guestbook, i call this method as <dtml-var addEntryAction> and it works. whereas the addEntryAction calls <dtml-call expr="addEntry(arg1, arg2,...)">
i thought this should work in another folder X too by writing <dtml-var "PARENTS[-1].GuestBook.addEntry(arg1,arg2,...)">
should it not?
If your method does not require any arguments, you can call it like this: <dtml-var "PARENTS[-1].GuestBook.addEntry()"> You can't omit the parentheses when using python expression syntax to call a method. Again, I would *strongly* suggest moving your application logic into Python scripts instead. You'll find that Python is easier to learn than you think, and the script objects will be much easier to write and maintain than Python expressions in DTML tags. -- Michael R. Bernstein <webmaven@lvcm.com>
Sungmook Kim wrote at 2003-2-9 00:19 +0100:
yep, it's a method. but within the folder guestbook, i call this method as <dtml-var addEntryAction> and it works. whereas the addEntryAction calls <dtml-call expr="addEntry(arg1, arg2,...)">
i thought this should work in another folder X too by writing <dtml-var "PARENTS[-1].GuestBook.addEntry(arg1,arg2,...)">
should it not?
Unless "addEntry" is a DTML object. If it is, two positional parameters ("client" and "REQUEST") are usually mandatory. More info in the section "Calling DTML objects" of <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
participants (3)
-
Dieter Maurer -
Michael R. Bernstein -
Sungmook Kim