[Zope] Bag 'o newbie questions

Michael S. Fischer michael@dynamine.net
Fri, 16 Aug 2002 14:28:28 -0700


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