Menu and Page Menus

Hello. My name is Ian G… I am new to Radiant and new to ruby.

I am trying to figure out how I can get the menu for pages I create to
be autogenerated for me, like the breadcrumbs. I was thinking it would
involve the radius tags and maybe the creation of a behavior so that
if I create a page part say: sidebar then I could include a tag say
<r:menu /> then I could make it so that it automatically creates a
menu based on the pages from the root all the way down to the current
page.

Anyway, let me know if anyone thinks this is worthwhile and how I
might go about implementing it.


Ian G.
Ian G. Online
http://www.iangordon.us

Hi Ian,

There is a recent thread dealing with this issue, you can check it out
on the ruby-forum archive here http://www.ruby-forum.com/topic/81640

No one has posted a complete solution yet, but there are a few ideas
floating around in there and definately some interest in getting
something made.

Kev

On 18/09/06, Ian G. [email protected] wrote:

Anyway, let me know if anyone thinks this is worthwhile and how I
might go about implementing it.

I’d be very interested to see what you come up with for this :slight_smile:

Rather than a behaviour, perhaps a ‘Global Tag’ is more like what you
want to make:

http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags


Regards,
Dave

Dave C. wrote:

I’d be very interested to see what you come up with for this :slight_smile:

Rather than a behaviour, perhaps a ‘Global Tag’ is more like what you
want to make:

http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags


Regards,
Dave

I am too Dave, I am too…

You may be able to modify the “sitemap” snippet that’s on the wiki to do
just that, perhaps with only one global tag creation. I’ve been mulling
around how to do this. I’ll get back to you. (I sense a new “how to”
article.)

Sean C.
seancribbs.com

Ok, I’ve got it. Let’s take the “sitemap” snippet from the wiki and
modify
it.

The part we’ll put in our page will look like this:

The sitemapper snippet, slightly modified:

<r:if_ancestor_or_self>
<r:children:each by=“title” order=“asc”>
<r:unless_content part=“no-map”>


  • <r:link />

      <r:snippet name=“sitemapper” />


  • </r:unless_content>
    </r:children:each>
    </r:if_ancestor_or_self>

    Then our new global tag definition (I’m using the PageContext syntax):

    define_tag ‘if_ancestor_or_self’ do |tag|
    page = tag.globals.page
    ancestors = tag.globals.page.ancestors
    context_page = tag.locals.page
    tag.expand if context_page == page or
    ancestors.include?(context_page)
    end

    This should, starting from the root page, create a contextual menu
    including
    the siblings of all of the parent pages and the children of the current
    page.

    Let me know how that works out!

    Sean C.
    seancribbs.com

    Hi Guys,

    Unfortunately there appears to be some core behaviour stopping Seans
    code above from working - see trac ticket
    http://dev.radiantcms.org/radiant/ticket/450

    I’ve put my own stopgap solution together, utilizing the logic that Sean
    posted:


    class Behavior::Base
    class TagError < StandardError; end

    define_tags do

    tag 'menu' do |tag|
      url = tag.attr['url']
      if found = Page.find_by_url(tag.attr['url'])
        menu_root = found
      else
        menu_root = Page.find_by_url("/")
      end
    
      root_page = tag.locals.page
      ancestors = root_page.ancestors
    
      result = "<ul>\n"
      menu_root.children.each do |child|
        context_page = child
        result << recurse_menu(root_page, context_page, ancestors)
      end
      result << "</ul>\n"
    end
    

    end

    def recurse_menu(root_page, context_page, ancestors)
    result = “

  • <a
    href=”#{context_page.url}">#{context_page.title}\n"
    if context_page.has_children? && (root_page == context_page ||
    ancestors.include?(context_page))
    result << “
      \n”
      context_page.children.each do |child|
      result << recurse_menu(root_page, child, ancestors)
      end
      result << “
    \n”
    end
    result << “
  • \n”
    end
    end

    If anyone thinks it would be worthwhile, I can see what I can do about
    packaging this up into a plugin.

    Kevin A.
    http://www.digitalblueprint.co.uk

    Because of a limitation in the way that snippets are rendered, the code
    I
    posted earlier will not limit which children of the root of your sitemap
    are
    rendered. Essentially, everytime you get to the <r:if_ancestor_or_self>
    tag, tag.globals.page will equal tag.locals.page. I intend to leave a
    more
    detailed ticket on the Trac.

    Cheers,

    Sean C.
    seancribbs.com

    On 21/09/06, Kevin A. [email protected] wrote:

    If anyone thinks it would be worthwhile, I can see what I can do about
    packaging this up into a plugin.

    Yes please! :slight_smile:


    Regards,
    Dave

    Kevin A. wrote:

    ---- truncated ----

    If anyone thinks it would be worthwhile, I can see what I can do about
    packaging this up into a plugin.

    You don’t even have to ask man, just do it and if people like it
    awesome, if they don’t hey, at least you contributed.

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs