Navigation Tags help

Hi folks,

I have a set of navigation tags here:

Basically, it lets you build nested navigation like you see here:

The idea is to expand the navigation below the page that you’re
currently on. So if you’re on the “About” page, you see only the two
top-level items, but if you go to the “Blog” page, you see that
page’s sub-pages in the nav.

The trouble is that the tags are very slow - rendering the page can
take as long as 2-3 seconds on a big site. (Once the page is cached,
it loads very quickly of course.) If anyone would like to help me
figure out how to make this work faster, your help would be much

Here are the snippets that I use to generate that navigation:


SNIPET: sub-nav
<r:unless_content part=“no-map”>
<li<r:if_self> class=“current”</r:if_self>><r:link />

    <r:snippet name=“sub-nav” />


As far as I can tell, it’s the “if_ancestor_or_self” tag that’s
slowing it down. Here is the content of navigation_tags.rb:

module StandardTags
include Radiant::Taggable

Inspired by this thread:[email protected]/

desc %{
Renders the contained element if the current item is an ancestor
of the current page or if it is the page itself.
tag “if_ancestor_or_self” do |tag|
tag.expand if (tag.globals.actual_page.ancestors +

desc %{
Renders the contained element if the current item is also the
current page.
tag “if_self” do |tag|
tag.expand if == tag.globals.actual_page

desc %{
Renders the contained elements only if the current contextual
page has children.


tag “if_children” do |tag|
children =
tag.expand if children.size > 0


One optimization you might be able to make to the if_ancestor_or_self
(which normally could result in tons of DB calls) is to match the URL of
the page in the iteration against the actual page. If the first part
matches, then expand. Of course, this breaks if your site gets complex
– virtual pages and such are the usual culprits.

tag ‘if_ancestor_or_self’ do |tag|
tag.expand if