referencing title value as a var name
Goodday, My first question is that is it possible to store the title value of an object with <dtml-let> and later reference it with <dtml-if > in another object? if it is possible, pls furnish me with the deatils. Else i think i better explain what i actually have in mind. What i wanted is to list the titles of all the dtml documents in a folder, set the hyperlink of each dtml document to its id and finally store the value of the clicked title in a variable name. I think I am able to scale through this, but my problem now is to reference that variable name in another object. Below is the code i used to iterate and store the title value; this code is on one object called content_html: <ul> <dtml-in "objectValues(['DTML Document'])" sort=title> <li> <a href="&dtml-id;/">&dtml-title; <dtml-let dname="_['sequence-var-title']"> </dtml-let> </a> </li> </dtml-in> </ul> Below here is where i am having a problem, the code here is on another object called index_html but both content_html and index_html are in the same folder. <dtml-let dday=dname> <dtml-if expr="dday[0:6]=='Saturd'"> <dtml-var saturday2> <dtml-elif expr="dday[0:6]=='Friday'"> <dtml-var friday2> <dtml-elif expr="dday[0:6]=='Sunday'"> <dtml-var sunday2> <dtml-else> <dtml-var table2> </dtml-if> </dtml-let> Help in any form will be highly appreciated. Thanks. kamal.
Hamzat kamal wrote:
Goodday,
My first question is that is it possible to store the title value of an object with <dtml-let> and later reference it with <dtml-if > in another object? if it is possible, pls furnish me with the deatils. Else i think i better explain what i actually have in mind.
What i wanted is to list the titles of all the dtml documents in a folder, set the hyperlink of each dtml document to its id and finally store the value of the clicked title in a variable name. I think I am able to scale through this, but my problem now is to reference that variable name in another object.
Below is the code i used to iterate and store the title value; this code is on one object called content_html:
<ul> <dtml-in "objectValues(['DTML Document'])" sort=title> <li> <a href="&dtml-id;/">&dtml-title; <dtml-let dname="_['sequence-var-title']"> </dtml-let> </a> </li> </dtml-in> </ul>
Below here is where i am having a problem, the code here is on another object called index_html but both content_html and index_html are in the same folder.
<dtml-let dday=dname> <dtml-if expr="dday[0:6]=='Saturd'"> <dtml-var saturday2> <dtml-elif expr="dday[0:6]=='Friday'"> <dtml-var friday2> <dtml-elif expr="dday[0:6]=='Sunday'"> <dtml-var sunday2> <dtml-else> <dtml-var table2> </dtml-if> </dtml-let>
Help in any form will be highly appreciated.
Thanks.
kamal.
Anything you put inside a DTML let (including other object calls by name) have access to the name. However, I'm not convinced that you even need it to be this complex. From what I see, the first word of the title is a day, and based on that day value, you want to call another method/object. What I would do is get the first word of the title and try to call an object by that name (You'll need to create 7 objects: Monday, Tuesday, Wednesday... etc), and failing that call the table2 object. Like so: <dtml-in expr="objectValues('DTML Document')" sort="title"> <li> <a href="&dtml-id;/">&dtml-title; <dtml-let day="_.string.split(title)[0]"> <dtml-try> <dtml-var expr="_[day]"> <dtml-except NameError KeyError> <dtml-var name="table2"> </dtml-try> </dtml-let> </a> </li> </dtml-in> This avoids all those if/elifs. The key is _[day] which looks up the object whose name is the value of the variable day, which is set to the first word of the title using string.split (which splits a string on whitespace into a list) and retreiving the first item of the list. hth, -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
Casey Duncan wrote:
Anything you put inside a DTML let (including other object calls by name) have access to the name. However, I'm not convinced that you even need it to be this complex. From what I see, the first word of the title is a day, and based on that day value, you want to call another method/object. What I would do is get the first word of the title and try to call an object by that name (You'll need to create 7 objects: Monday, Tuesday, Wednesday... etc), and failing that call the table2 object. Like so:
<dtml-in expr="objectValues('DTML Document')" sort="title"> <li> <a href="&dtml-id;/">&dtml-title; <dtml-let day="_.string.split(title)[0]"> <dtml-try> <dtml-var expr="_[day]"> <dtml-except NameError KeyError> <dtml-var name="table2"> </dtml-try> </dtml-let> </a> </li> </dtml-in>
This avoids all those if/elifs. The key is _[day] which looks up the object whose name is the value of the variable day, which is set to the first word of the title using string.split (which splits a string on whitespace into a list) and retreiving the first item of the list.
Hi! I have same problem. Could you help me? This is the source: <dtml-in SelectState size=10 start=query_start> <dtml-var expr="_['STATE']"> </dtml-in> SelectState is a ZSQL method, gives the STATE, STATE is an integer, and there are three DTML DOCUMENT (named 0, 1, 2) in the folder, and these objects contains the "state string" (for example "OK", "Connection error" etc.) If I use the code above, I get only 0, 1 or 2, not the state strings. I tried <dtml-var expr="_[STATE]"> too, but it gives these erorrs. Error Type: SystemError Error Value: bad argument to internal function Thank you: Lajos Kerekes
Kerekes Lajos wrote:
Hi!
I have same problem. Could you help me? This is the source:
<dtml-in SelectState size=10 start=query_start> <dtml-var expr="_['STATE']"> </dtml-in>
SelectState is a ZSQL method, gives the STATE, STATE is an integer, and there are three DTML DOCUMENT (named 0, 1, 2) in the folder, and these objects contains the "state string" (for example "OK", "Connection error" etc.)
If I use the code above, I get only 0, 1 or 2, not the state strings.
I tried <dtml-var expr="_[STATE]"> too, but it gives these erorrs. Error Type: SystemError Error Value: bad argument to internal function
Thank you:
Lajos Kerekes
I think that is because STATE is an integer, and _[ ] expects a string. try: <dtml-var expr="_[_.str(STATE)]"> kinda messy looking, but it should work. hth, -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
Hi Kerekes, I think using a DTML document only as container for a single string to look up is a bit overworked ;) What about a single lines Property with the words you want int the given order and then: <dtml-var expr="StateProperty[STATE]"> This will work with integer as lookup. Regards Tino --On Dienstag, 14. August 2001 08:28 -0600 Casey Duncan <cduncan@kaivo.com> wrote:
Kerekes Lajos wrote:
Hi!
I have same problem. Could you help me? This is the source:
<dtml-in SelectState size=10 start=query_start> <dtml-var expr="_['STATE']"> </dtml-in>
SelectState is a ZSQL method, gives the STATE, STATE is an integer, and there are three DTML DOCUMENT (named 0, 1, 2) in the folder, and these objects contains the "state string" (for example "OK", "Connection error" etc.)
If I use the code above, I get only 0, 1 or 2, not the state strings.
I tried <dtml-var expr="_[STATE]"> too, but it gives these erorrs. Error Type: SystemError Error Value: bad argument to internal function
Thank you:
Lajos Kerekes
I think that is because STATE is an integer, and _[ ] expects a string. try:
<dtml-var expr="_[_.str(STATE)]">
kinda messy looking, but it should work.
hth, -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Casey Duncan -
Hamzat kamal -
Kerekes Lajos -
Tino Wildenhain