I'm trying to include code in my standard_html_footer that checks to see if I'm more than 2 folders deep in the site. If so, I want a back button. why doesn't this work? It fails if PARENTS[1] evaluates to false. <dtml-if "PARENTS[1]"><a href="<dtml-var "PARENTS[1].absolute_url()">">back</a></dtml-if> last lines of traceback: File /usr/local/src/Zope-2.0.0-src/lib/python/DocumentTemplate/DT_Util.py, line 321, in eval (Object: PARENTS[1]) File <string>, line 0, in ? File /usr/local/src/Zope-2.0.0-src/lib/python/DocumentTemplate/DT_Util.py, line 156, in careful_getitem IndexError: list index out of range (zope 2.0.0), i know about the security issue & will upgrade before going live. -- Ethan "mindlace" Fremen you cannot abdicate responsibility for your ideology.
Don't know why it doesn't work, but you could probably work around it by using Python's len function on PARENTS. -- Loren
-----Original Message----- From: mindlace@turtle.esosoft.net [mailto:mindlace@turtle.esosoft.net]On Behalf Of Ethan Fremen Sent: Monday, November 22, 1999 09:32 To: zope@zope.org Subject: [Zope] depthfinder
I'm trying to include code in my standard_html_footer that checks to see if I'm more than 2 folders deep in the site. If so, I want a back button.
why doesn't this work? It fails if PARENTS[1] evaluates to false.
<dtml-if "PARENTS[1]"><a href="<dtml-var "PARENTS[1].absolute_url()">">back</a></dtml-if>
last lines of traceback:
File /usr/local/src/Zope-2.0.0-src/lib/python/DocumentTemplate/DT_Util.py, line 321, in eval (Object: PARENTS[1]) File <string>, line 0, in ? File /usr/local/src/Zope-2.0.0-src/lib/python/DocumentTemplate/DT_Util.py, line 156, in careful_getitem IndexError: list index out of range
(zope 2.0.0), i know about the security issue & will upgrade before going live. -- Ethan "mindlace" Fremen you cannot abdicate responsibility for your ideology.
_______________________________________________ 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 )
On Mon, 22 Nov 1999, Ethan Fremen wrote:
why doesn't this work? It fails if PARENTS[1] evaluates to false.
<dtml-if "PARENTS[1]"><a href="<dtml-var "PARENTS[1].absolute_url()">">back</a></dtml-if>
last lines of traceback:
IndexError: list index out of range
The error message said it all - list index out of range. Read: there is no PARENTS[1], only PARENTS[0]. Test "_.len(PARENTS) > 1"... Oleg. ---- Oleg Broytmann Foundation for Effective Policies phd@phd.russ.ru Programmers don't die, they just GOSUB without RETURN.
I imagine this would be an excellent opportunity to learn the <dtml-try> ... <dtml-except> ... </dtml-try> tags. They make truly wonderful ways around errors you don't expect, and in this case, some that you do. But would this be considered cheating? -- Jim Washington Oleg Broytmann wrote:
On Mon, 22 Nov 1999, Ethan Fremen wrote:
why doesn't this work? It fails if PARENTS[1] evaluates to false.
<dtml-if "PARENTS[1]"><a href="<dtml-var "PARENTS[1].absolute_url()">">back</a></dtml-if>
last lines of traceback:
IndexError: list index out of range
The error message said it all - list index out of range. Read: there is no PARENTS[1], only PARENTS[0]. Test "_.len(PARENTS) > 1"...
Oleg. ---- Oleg Broytmann Foundation for Effective Policies phd@phd.russ.ru Programmers don't die, they just GOSUB without RETURN.
Thanks, all! Here's the final code snippet- it places a "back" link on every page more than 1 folder down in the site, and changes behavior appropriately whether it's being rendered in a Document or a Method: <dtml-if "_.len(PARENTS) > 2"> <dtml-if "meta_type == 'DTML Document'"><a href="<dtml-var "PARENTS[0].absolute_url()">"> <dtml-else><a href="<dtml-var "PARENTS[1].absolute_url()">"></dtml-if> back</a></dtml-if> -- Ethan "mindlace" Fremen you cannot abdicate responsibility for your ideology.
Here's the final code snippet- it places a "back" link on every page
Shouldn't that be an 'up' link? :) -jfarr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hi! I'm a signature virus. Copy me into your .sig to join the fun! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ethan Fremen wrote:
Thanks, all!
Here's the final code snippet- it places a "back" link on every page more than 1 folder down in the site, and changes behavior appropriately whether it's being rendered in a Document or a Method:
<dtml-if "_.len(PARENTS) > 2"> <dtml-if "meta_type == 'DTML Document'"><a href="<dtml-var "PARENTS[0].absolute_url()">"> <dtml-else><a href="<dtml-var "PARENTS[1].absolute_url()">"></dtml-if> back</a></dtml-if>
Funny thing, I was working on this myself lastnight :-) I wound up using : <dtml-if URL2> .... </dtml-if> I am using it to generate a list of folders and their subfolders ;-) (Yes, there will be a neat little howto for it soon (including your code above, IYDM) :-) Bill -- "They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown." -- Carl Sagan
participants (6)
-
Bill Anderson -
Ethan Fremen -
Jim Washington -
Jonothan Farr -
Loren Stafford -
Oleg Broytmann