Randal L. Schwartz wrote:
Anything you leave in "global" will be visible the next time with the
same context.
Thanks, that worked!  For reference, I've attached my breadcrumbs implementation.  I pre_process lib/breadcrumbs.tmpl, which loads my XML sitemap file via XPath and defines a "breadcrumbs" block that walks up the XML tree to generate the breadcrumbs when processed by the wrapper.

sitemap.xml has a very simple XML vocabulary with tag encapsulation defining the breadcrumbs hierarchy.  The principle benefit of this approach over walking the filesystem path is that I don't have to make my filesystem hierarchy mimic my site structure or move files around and change URLs when the structure changes.

lib/breadcrumbs.tmpl and lib/sitemap.xml included below.  (Hmm, now that I write this I wonder if the blocks can be cached as well.)

-myk

lib/breadcrumbs.tmpl:

[%# Load the sitemap once per build and cache it for reuse on each page. %]
[% IF !global.cached.xpath %]
  [% USE xpath = XML.XPath("lib/sitemap.xml") %]
  [% global.cached.xpath = xpath %]
[% END %]

[% BLOCK breadcrumbs %]
  [% path = "//[EMAIL PROTECTED]'${template.name}']" %]
  [% nodes = [global.cached.xpath.findnodes(path)] %]
  [% PROCESS crumb crumbs=[] node=nodes.0 %]

  [% FOREACH crumb IN crumbs.reverse %]
    <a href="">[% crumb.title %]</a> [% ">" UNLESS loop.last() %]
  [% END %]
[% END %]

[% BLOCK crumb %]
  [% IF node && node.getName() == "page" %]
    [% crumbs.push({ title => node.getAttribute("title"),
                     url   => node.getAttribute("url") }) %]
    [% PROCESS crumb node=node.getParentNode() %]
  [% END %]
[% END %]

lib/sitemap.xml:

<?xml version="1.0" encoding="UTF-8"?>

<page url="" title="Home">
  <page url="" title="Test" />
</page>

-myk





Reply via email to