[Zope] Fun with Trees
Rik Hoekstra
rik.hoekstra@inghist.nl
Mon, 03 Jul 2000 09:35:06 +0200
Charlie Wilkinson writes:
After RTFMing and flailing at DTML all night, I'm about stumped.
No pun intended.
I'm trying to use dtml-tree to create a selective menu of objects based
on whether or not the object has an "add_to_menu" property. I've pretty
much figured out that I need a wrapper around objectValues that will
filter out the objects that don't have the "add_to_menu" property.
This wrapper would be called with dtml-tree's "branches" attribute.
I'm trying to do this wrapper in a DTML method and I've gotten all the
way to where I have to return a list of "actual objects", so says the
DTML Quick Reference.
Is there someone who could 'splain to me how to build a list of objects
in DTMLese?
Here's what I have so far (obviously not working):
<dtml-call "REQUEST.set('ret', '')">
<dtml-in "objectValues()" sort=id>
<dtml-if "_.has_key('add_to_menu')">
<dtml-call "REQUEST.set('ret', ret + ' ' + _['sequence-item'])">
</dtml-if>
</dtml-in>
<dtml-return "_.string.split(ret)">
[rh]
Try (yes, this is tested):
<dtml-call "REQUEST.set('ret', '')">
<dtml-in "objectValues()" sort=id>
<dtml-if "_.has_key('add_to_menu')">
<dtml-call "ret.append(id)">
</dtml-if>
</dtml-in>
<dtml-return ret>
Two notes:
- the string approach is an unnecessary hack. I changed it to standard
Python list idiom
- if you append sequence-item it will include your whole method, which
presumably is not what you want in your tree. Use id.
HTH
Rik