[Zope] Navigation menu
J. Cameron Cooper
jccooper at jcameroncooper.com
Sun Jan 18 18:21:04 EST 2004
Michael Havard wrote:
> I've been looking for a navigation menu/sitemap for ZOPE. I've found a
> few but the output is not very well formed.
>
> Essentially every tool I've found outputs something similar to this:
>
> <div class="item" style="text-indent:35">
> <!-- this is a parent element //-->
> Item
> </div>
> <div class="item" style="text-indent:65">
> <!-- this is a child element //-->
> Child Item
> </div>
>
> The problem here is that the html structure doesn't intrisicly show
> any relationship between the two levels. The code just shows levels by
> using text-indent or margins or in some code table cells. What I'm
> looking for would display the sitemap/navigation in a format like this:
>
> <ul>
> <li>Item
> <ul>
> <li>Child Item</li>
> </ul>
> </li>
> </ul>
>
> This structure has the element relationship built in by design. Does
> anyone know of a product that does this or have a code snippet they
> could pass my way.
Here's something that I use for generation of a navigation tree. You can
simplify it by removing the highlighting stuff and the styling stuff
that interfaces with TransMenus
(http://personal.archomai.org/transMenus.php).
Some things specific to my code and probably not yours:
- course: a previously defined value for the object the tree should
start at. You could use 'root' or 'context' or something else.
- equivalency test: mine is for Archetypes objects. You'll need some
other testif you don't have UIDs.
- children listing: mine is project-specific. You can probably use
'objectValues' or 'contentValues'
- groupishness: again, mine is project-specific, an attribute on
groupish types. You could use truthfullness of the children-listing as
above.
Also, I've previously posted several times a simpler recursive
tree-walker that works similarly, but with less METAL magic.
ZPT::
...
<ul id="collapsibleDemo">
<li tal:define="highlight python: course.UID()==here.UID()">
<span tal:attributes="class python:highlight and
'ccCurrentElt' or None">
<a href="." tal:attributes="href course/absolute_url">
<img src="site_icon.gif" tal:replace="structure
python:path('here/%s' % course.getIcon(1))"
tal:on-error="structure here/site_icon.gif"
/></a> <a href="." tal:attributes="href
course/absolute_url" tal:content="course/Title">Element</a>
</span> <img tal:replace="structure
here/transmenus/arrow.png" tal:condition="highlight" />
<ul tal:repeat="elt course/children">
<span metal:use-macro="template/macros/recursivetree" />
</ul>
</li>
</ul>
...
<tal:macros tal:replace="nothing">
<metal:li metal:define-macro="recursivetree">
<li tal:define="highlight python: elt.UID()==here.UID()">
<span tal:attributes="class python:highlight and 'ccCurrentElt' or None">
<a href="." tal:attributes="href elt/absolute_url">
<img src="site_icon.gif" tal:replace="structure
python:path('here/%s' % elt.getIcon(1))"
tal:on-error="structure here/site_icon.gif"
/></a> <a href="." tal:attributes="href elt/absolute_url"
tal:content="elt/Title">Element</a>
</span> <img tal:replace="structure here/transmenus/arrow.png"
tal:condition="highlight" />
<tal:groupish tal:condition="exists:elt/aq_explicit/isGroup">
<ul class="collapsibleMenu" tal:condition="elt/children">
<tal:block tal:repeat="elt elt/children">
<span metal:use-macro="template/macros/recursivetree" />
</tal:block>
</ul>
</tal:groupish>
</li>
</metal:li>
</tal:macros>
--
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."
More information about the Zope
mailing list