cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make a breadcrumb in Surf?

darryl_staflund
Champ in-the-making
Champ in-the-making
Hi all,

Does anybody have any recommendations on how I can create a breadcrumb in Surf?  I am developing a website with a traditional tree-like structure and I had originally decided on adopting the following strategy for building a breadcrumb at the top of my pages (NB:  The following is just pseudocode):


    var breadcrumbs = [];

    function buildBreadcrumb (page) {
         if page == null
             return;
         else
             breadcrumbs.push (page);
             buildBreadcrumb (page.parent);
    }

    return breadcrumbs.reverse ();

In order to get this working, I need to be able to associate child pages with their parent (not the other way around.)  This doesn't seem to be easy to do in Surf though.  Originally I had tried to create page associations with 'child' relations as follows:


    <page-association>
        <source-id>child_page</source-id>
        <dest-id>parent_page</dest-id>
        <assoc-type>parent</assoc-type>
    </page-association>

and then use a Javascript function of the following form:


    sitedata.findPageAssociations('child_page', 'parent');

but no such function exists.  The closest I could find was:


    sitedata.findPageAssociations('child_page', 'parent_page', 'parent');

The problem, though, is that it is precisely the parent page I am trying to identify.

Any ideas on how I might be able to do this?

Thanks,
Darryl
1 REPLY 1

lingling
Champ in-the-making
Champ in-the-making
Having had a similar problem myself I devised a work around by putting the parent page id as a property in the page details.

example:
<?xml version="1.0" encoding="UTF-8"?>
<page>
   <title>some title</title>
   <description>some description</description>
      <template-instance>some-template</template-instance>
      <properties>
         <parent>parent_page_id</parent>
      </properties>
</page>

You can then access the parent page as follows:

sitedata.getPage(context.page.properties["parent"])

hope this helps,
-L