Breadcrumbs Using a Filter - Mach-II/Mach-II-Framework GitHub Wiki

Breadcrumb example app is attached (see below). Demo site.

To use the filter, define it in the <event-filters> section of your config.xml:

    <event-filter name="BreadCrumbsFilter" type="CrumbsExample.filters.BreadCrumbsFilter">
        <parameters>
            <parameter name="HomeEvent" value="Home" />
            <parameter name="HomeText" value="Home" />
            <parameter name="TrailMax" value="6" />
        </parameters>
    </event-filter>
  • HomeEvent is the name of your default or home event name.
  • HomeText can be something more user friendly. This is what will display in crumb trail.
  • TrailMax is arbitrary, but could be useful if you need it.

To have an event show up in the crumb trail, within an <event-handler>, put this:

    <filter name="BreadCrumbsFilter">
        <parameter name="page" value="Home" />
        <parameter name="isEntryPoint" value="true" />
    </filter>

The page parameter is what will be displayed in the crumb trail. isEntryPoint is optional and defaults to false. Setting it to true will reset the trail and make that event the first in the trail (after Home).

The output can be found in the /views/nav.cfm page. Put it where ever makes sense for your layout.

In the filter, you'll see some code referring to window number or "wn". This was my attempt to handle links that open new windows or tabs. I did not get too far with this and for now everything defaults to 1.

If you want to have your home event always display by default add the following condition:

    <cfif local.thisEvent NEQ variables.HomeEvent>

so that lines 103 - 110 are the following:

    <!--- If event was found, delete everything from end of trail to that point. --->
    <!--- we want to show the home crumb by default so add this condition --->
    <cfif local.thisEvent NEQ variables.HomeEvent>
        <cfif local.deleteFrom GT 0>
            <cfloop from="#arrayLen(local.ary_thisCrumbTrail)#" to="#local.deleteFrom#" index="local.j" step="-1">
                <cfset ArrayDeleteAt(local.ary_thisCrumbTrail,local.j)>
            </cfloop>
        </cfif>
    </cfif>

Attachments

⚠️ **GitHub.com Fallback** ⚠️