Breadcrumbs Navigation Trail
Created by .
Last modified on 2003/08/05.
This method creates the text for a type of navigation bar (like you see at Yahoo!) which consists of hyperlinks to each of the parent objects of the current object; for example:
Home > Admin > Events > Christmas Party
All the logic that depends on (meta_type == 'Message') or (meta_type == 'Reply') handles some complications introduced by Confera Topics. If you don't have any Confera Topics, you can delete the extra logic.
<!-- Start Breadcrumbs -->
<dtml-unless expr="PARENTS[0]==PARENTS[-1]">
<dtml-call "REQUEST.set('reverse_PARENTS', [])">
<dtml-call "REQUEST.set('reverse_LAST', 0)">
<dtml-in PARENTS skip_unauthorized>
<dtml-if expr="(meta_type == 'Message') or (meta_type == 'Reply')">
<dtml-unless "reverse_LAST==1">
<dtml-call "reverse_PARENTS.insert(0, _['sequence-item'])">
<dtml-call "REQUEST.set('reverse_LAST', 1)">
</dtml-unless>
<dtml-else>
<dtml-call "reverse_PARENTS.insert(0, _['sequence-item'])">
</dtml-if>
</dtml-in>
<dtml-in reverse_PARENTS>
<dtml-if sequence-start><a href="/">Home</a>
<dtml-else>
<dtml-if sequence-end>
<dtml-unless expr="(meta_type == 'Message') or (meta_type == 'Reply')">
> <font size="+1" color="#990000"><b><dtml-var title_or_id></b></font>
</dtml-unless>
<dtml-else>
<dtml-if expr="(meta_type == 'Message') or (meta_type == 'Reply')">
> <a href="<dtml-var absolute_url>"><dtml-var title_or_id></a>
<dtml-else>
> <a href="<dtml-var absolute_url>"><dtml-var id></a>
</dtml-if>
</dtml-if>
</dtml-if>
</dtml-in>
</dtml-unless>
<!-- End Breadcrumbs -->
Here's another implementation by Barry A. Warsaw. This version allows you to assign an optional "nickname" property to any folder. If a nickname exists, it is displayed instead of the folder's ID (which might be irrelevant) or title (which might be too long). Also, the Confera logic has been deleted, making things much simpler.
<!-- start Breadcrumbs -->
<dtml-call "REQUEST.set('rev', [])">
<dtml-in PARENTS skip_unauthorized>
<dtml-let item=sequence-item>
<dtml-call "rev.insert(0, item)">
</dtml-let>
</dtml-in>
<dtml-in rev>
<dtml-with sequence-item>
<a href="<dtml-var absolute_url>">
<dtml-if "hasProperty('nickname')"><dtml-var nickname><dtml-else><dtml-var title_or_id></dtml-if></a>
</dtml-with>
<dtml-unless sequence-end> >
</dtml-unless>
</dtml-in>
<!-- end Breadcrumbs -->
Put one of the above code examples in a DTML method (called, for example, "breadcrumbs"), then invoke the method where you want the breadcrumbs to show (most likely in "standard_html_header"):
<dtml-var breadcrumbs>
If you have a view_source method implemented on your site, you may experience infinite recursion. If so, try this:
<dtml-unless "_['URL'][-11:] == 'view_source'">
<dtml-var breadcrumbs>
</dtml-unless>
|