Forum: Radiant CMS Navigation Tags help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
66ea50b15982d1b33aeaaa6df0d7a1dd?d=identicon&s=25 Ryan Heneise (Guest)
on 2007-06-08 22:18
(Received via mailing list)
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:

<div id="nav">
   <r:find url="/">
<r:snippet name="sub-nav" />

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:
   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

8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-06-08 22:24
(Received via mailing list)
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


This topic is locked and can not be replied to.