[%
# 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;
my_path = "${template.name}"|replace('/index.html|/index.en.html','/')|replace('.html|.en.html','');
nodes = [global.cached.xpath.findnodes("//page[@url='$my_path']")];
UNLESS nodes;
my_id = "${template.name}"|replace('/index.html|/index.en.html|.html|.en.html','')|replace('^.+/','');
nodes = [global.cached.xpath.findnodes("//page[@id='$my_id']")];
END;
PROCESS crumb crumbs=[] node=nodes.0;
u = "";
FOREACH crumb IN crumbs.reverse;
IF loop.first;
"Home ";
END;
" » ";
IF loop.last;
"$crumb.title";
ELSE;
IF crumb.url;
u = "$crumb.url";
ELSE;
u = "$u/$crumb.id";
END;
"$crumb.title";
END;
END;
END;
BLOCK crumb;
IF node && node.getName() == "page";
crumbs.push({ title => node.getAttribute("title"),
id => node.getAttribute("id"),
url => node.getAttribute("url") });
PROCESS crumb node=node.getParentNode();
END;
END;
%]