Hi folks, I'm fairly new to Zope, but I have about a year's worth of Python experience so I understand it reasonably well. I'm trying to convert my employer's internal engineering web server to Zope. On the present site there's some functionality I coded in PHP for which I'd like to create Zope equivalents. I'd appreciate any comments or help you can offer. 1) We used PHP's "auto_prepend_file" and "auto_append_file" directives to paste in a standard header and footer to every HTML document below the root. Is there a facility by which we can do this in Zope without having each page explicitly call <dtml-var> to render the header and footer? 2) I wrote a left-side navbar that displays the directory tree of the site. Lucky me! <dtml-tree> seems to be capable of generating an even nicer one. Our site's directory tree looks like this: /index_html (DTML document) /standard_html_footer (DTML method) /standard_html_header (DTML method) /a/index_html (DTML document) /a/aa/index_html (...) /b/index_html /c/index_html /c/cc/index_html /d/index_html /d/dd/ <-- note the lack of index page here /d/dd/ddd/index_html And so on. I copied over our index pages for /index_html and /a/index_html, and modified them so that they call <dtml-var standard_html_header> and <dtml-var standard_html_footer>. In standard_html_header, I make a <dtml-tree> call. Here are the issues I've run into: a) <dtml-tree> won't render unless index_html is a DTML method (it won't work if index_html is a DTML document). Help me understand the namespace issue here: is it not sufficient that a DTML document is calling the DTML method that has the <dtml-tree> call? b) I want the <dtml-tree> call to render a tree rooted at / no matter which page a user is visiting. I tried encapsulating the <dtml-tree> call in a <dtml-with expr="PARENTS[-1]"> as described at <http://www.zopelabs.com/cookbook/1003151229> but when I visit /a/index_html I see a tree rooted at /a. What am I doing wrong? 3) In directories like /d/dd, where there is no index_html page, I do _not_ want to inherit a parent's index_html page; rather, I want to set up my own TOC generator for the directory. What's the best way to do this? 4) I'd like to examine the DTML namespace stack so I can understand it a little more deeply. What's the best way to do this? Thank you all so much for your help, -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
On Fri, Aug 09, 2002 at 02:40:16PM -0700, Michael S. Fischer wrote:
2) I wrote a left-side navbar that displays the directory tree of the site. Lucky me! <dtml-tree> seems to be capable of generating an even nicer one. Our site's directory tree looks like this:
I got tree to work a long time ago, but I actually got tired of the perpetual clickability of it. I exchanged it for an NFGNav-based navbar, and then for one written in Python and ZPT. Documented at http://www.zope.org/Members/mwr
3) In directories like /d/dd, where there is no index_html page, I do _not_ want to inherit a parent's index_html page; rather, I want to set up my own TOC generator for the directory. What's the best way to do this?
Untested code, assuming any designers you have don't mind editing pages not named index_html: index_html (acquired from root): <dtml-if "_.hasattr(this().aq_explicit, 'content_html')"> <dtml-var content_html> <dtml-else> <dtml-var toc_html> </dtml-if> Use content_html like you'd normally use index_html; use the dtml method toc_html to generate your toc. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
On Fri, Aug 09, 2002 at 11:03:31PM -0500, Mike Renfro wrote:
3) In directories like /d/dd, where there is no index_html page, I do _not_ want to inherit a parent's index_html page; rather, I want to set up my own TOC generator for the directory. What's the best way to do this?
Untested code, assuming any designers you have don't mind editing pages not named index_html:
index_html (acquired from root):
<dtml-if "_.hasattr(this().aq_explicit, 'content_html')"> <dtml-var content_html> <dtml-else> <dtml-var toc_html> </dtml-if>
I tried to rewrite this in ZPT, and I figured out this much: <span tal:condition="exists:container/aq_explicit/content_html" tal:replace="structure container/content_html"> </span> <span tal:condition="not:exists:container/aq_explicit/content_html" tal:replace="structure container/toc_html"> </span> This seems to work. I really wanted to write something like this, but I couldn't get it to work: <span tal:define="object python:test(hasattr(container.aq_explicit, 'content_html'), content_html, toc_html)" tal:replace="structure object"> </span> Apparently the test() function actually tries to evaluate the (possibly non-existing) content_html object even if the hasattr() returns 0. Any thoughts? -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
On Fri, Aug 16, 2002 at 02:28:28PM -0700, Michael S. Fischer wrote:
I really wanted to write something like this, but I couldn't get it to work:
<span tal:define="object python:test(hasattr(container.aq_explicit, 'content_html'), content_html, toc_html)" tal:replace="structure object"> </span>
Apparently the test() function actually tries to evaluate the (possibly non-existing) content_html object even if the hasattr() returns 0.
Any thoughts?
I'm still interested in the answer to the above question, but I found out this works just fine: <span tal:replace="structure here/aq_explicit/default_html | toc_html"> </span> -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
On Fri, Aug 16, 2002 at 02:46:09PM -0700, Michael S. Fischer wrote:
<span tal:replace="structure here/aq_explicit/default_html | toc_html"> </span>
Uh, I meant: <span tal:replace="structure here/aq_explicit/default_html | here/toc_html"> </span> -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
Michael S. Fischer wrote:
I really wanted to write something like this, but I couldn't get it to work:
<span tal:define="object python:test(hasattr(container.aq_explicit, 'content_html'), content_html, toc_html)" tal:replace="structure object"> </span>
Apparently the test() function actually tries to evaluate the (possibly non-existing) content_html object even if the hasattr() returns 0.
yup, that's how python works :-S You have to write it as: (hasattr(container.aq_explicit, 'content_html') and container.content_html) or here.toc_html ..which causes python to execute somewhat differently. That said, this is a bit more graceful: getattr(container.aq_explicit,'content_html',here.toc_html) However, you came up with quite a graceful solution, I'd code it as: <tal:x replace="structure here/aq_explicit/default_html | here/toc_html"/> cheers, Chris
Michael S. Fischer wrote:
I really wanted to write something like this, but I couldn't get it to work:
<span tal:define="object python:test(hasattr(container.aq_explicit, 'content_html'), content_html, toc_html)" tal:replace="structure object"> </span>
Apparently the test() function actually tries to evaluate the (possibly non-existing) content_html object even if the hasattr() returns 0.
yup, that's how python works :-S You have to write it as: (hasattr(container.aq_explicit, 'content_html') and container.content_html) or here.toc_html ..which causes python to execute somewhat differently. That said, this is a bit more graceful: getattr(container.aq_explicit,'content_html',here.toc_html) However, you came up with quite a graceful solution, I'd code it as: <tal:x replace="structure here/aq_explicit/default_html | here/toc_html"/> cheers, Chris
Michael S. Fischer writes:
1) We used PHP's "auto_prepend_file" and "auto_append_file" directives to paste in a standard header and footer to every HTML document below the root. Is there a facility by which we can do this in Zope without having each page explicitly call <dtml-var> to render the header and footer? Your options (there may be more):
* You present your objects through a specialized "view" method. It can add a header and footer as wanted. Drawback: your URL's must become "<path_to_your_object>/view". * You role out your own product (you may look at HTMLDocument for an example) * You use CMF, maybe in combination with your own product. Look at the "Document" class (for an example). * You use dynamic patching to override the "index_html" method of your objects. You set it to your "view" method above in the first option.
... a) <dtml-tree> won't render unless index_html is a DTML method (it won't work if index_html is a DTML document) That should be simple:
Forget about DTML Document. Only use DTML Methods.
Help me understand the namespace issue here: is it not sufficient that a DTML document is calling the DTML method that has the <dtml-tree> call? Read DTML objects in
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
b) I want the <dtml-tree> call to render a tree rooted at / no matter which page a user is visiting. I tried encapsulating the <dtml-tree> call in a <dtml-with expr="PARENTS[-1]"> as described at <http://www.zopelabs.com/cookbook/1003151229> but when I visit /a/index_html I see a tree rooted at /a. What am I doing wrong? Try (untested):
<dtml-let root="PARENTS[-1]"> <dtml-tree root ...> ...
3) In directories like /d/dd, where there is no index_html page, I do _not_ want to inherit a parent's index_html page; rather, I want to set up my own TOC generator for the directory. What's the best way to do this? You put your TOC generator in these folders and call it "index_html".
4) I'd like to examine the DTML namespace stack so I can understand it a little more deeply. What's the best way to do this? You can't (at least not easily).
Read "Name lookup" in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
On Sat, Aug 10, 2002 at 04:31:31PM +0200, Dieter Maurer wrote:
a) <dtml-tree> won't render unless index_html is a DTML method (it won't work if index_html is a DTML document) That should be simple:
Forget about DTML Document. Only use DTML Methods.
OK, no problem. This leads me to another question: how can one configure Zope such that a specific file suffix (e.g. .html) gets mapped to a DTML method (or some other arbitrary object type) instead of a DTML document when it's uploaded to ZServer via FTP or DAV? -- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
Hi Michael, See the bit about PUT_factory in http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/External Tools.stx . ----- Original Message ----- From: "Michael S. Fischer" <michael@dynamine.net> To: "Dieter Maurer" <dieter@handshake.de> Cc: <zope@zope.org> Sent: Monday, August 12, 2002 2:53 PM Subject: Re: [Zope] Bag 'o newbie questions
On Sat, Aug 10, 2002 at 04:31:31PM +0200, Dieter Maurer wrote:
a) <dtml-tree> won't render unless index_html is a DTML method (it won't work if index_html is a DTML document) That should be simple:
Forget about DTML Document. Only use DTML Methods.
OK, no problem. This leads me to another question: how can one configure Zope such that a specific file suffix (e.g. .html) gets mapped to a DTML method (or some other arbitrary object type) instead of a DTML document when it's uploaded to ZServer via FTP or DAV?
-- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
_______________________________________________ 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 )
Look for PUT_Factory on zope.org or in your source. http://www.zope.org/Wikis/DevSite/Proposals/HookablePUTCreation
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Michael S. Fischer Sent: Monday, August 12, 2002 11:53 AM To: Dieter Maurer Cc: zope@zope.org Subject: Re: [Zope] Bag 'o newbie questions
On Sat, Aug 10, 2002 at 04:31:31PM +0200, Dieter Maurer wrote:
a) <dtml-tree> won't render unless index_html is a DTML method (it won't work if index_html is a DTML document) That should be simple:
Forget about DTML Document. Only use DTML Methods.
OK, no problem. This leads me to another question: how can one configure Zope such that a specific file suffix (e.g. .html) gets mapped to a DTML method (or some other arbitrary object type) instead of a DTML document when it's uploaded to ZServer via FTP or DAV?
-- Michael S. Fischer / michael at dynamine.net / +1 650-533-4684 Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
_______________________________________________ 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 (6)
-
Charlie Reiman -
Chris McDonough -
Chris Withers -
Dieter Maurer -
Michael S. Fischer -
Mike Renfro