breadcrumbs.tmpl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [%
  2. # Load the sitemap once per build and cache it for reuse on each page.
  3. IF !global.cached.xpath;
  4. USE xpath = XML.XPath("lib/sitemap.xml");
  5. global.cached.xpath = xpath;
  6. END;
  7. BLOCK breadcrumbs;
  8. my_path = "${template.name}"|replace('/index.html|/index.en.html','/')|replace('.html|.en.html','');
  9. nodes = [global.cached.xpath.findnodes("//page[@url='$my_path']")];
  10. UNLESS nodes;
  11. my_id = "${template.name}"|replace('/index.html|/index.en.html|.html|.en.html','')|replace('^.+/','');
  12. nodes = [global.cached.xpath.findnodes("//page[@id='$my_id']")];
  13. END;
  14. PROCESS crumb crumbs=[] node=nodes.0;
  15. u = "";
  16. FOREACH crumb IN crumbs.reverse;
  17. IF loop.first;
  18. "<a href=\"$toplink\">Home</a> ";
  19. END;
  20. " &#187; ";
  21. IF loop.last;
  22. "<span>$crumb.title</span>";
  23. ELSE;
  24. IF crumb.url;
  25. u = "$crumb.url";
  26. ELSE;
  27. u = "$u/$crumb.id";
  28. END;
  29. "<a href=\"$toplink$u\">$crumb.title</a>";
  30. END;
  31. END;
  32. END;
  33. BLOCK crumb;
  34. IF node && node.getName() == "page";
  35. crumbs.push({ title => node.getAttribute("title"),
  36. id => node.getAttribute("id"),
  37. url => node.getAttribute("url") });
  38. PROCESS crumb node=node.getParentNode();
  39. END;
  40. END;
  41. %]