I've read this guide:
which is very helpful, however my client has asked something else of me. They want each page to have a sub-menu that lists the sub-pages of that page. So for instance, if they have 2 main pages, each with 3 sub-pages:
Education
videos
practice
documents
Certification
tests
practice
trials
The main navigation is shown via:
<%= Refinery::Pages::MenuPresenter.new(refinery_menu_pages, self).to_html %>
and this appears everywhere on the site, and the should show 2 links:
Education
Certification
However, when I'm on the Education page, I should see a sub-menu that shows:
videos
practice
documents
and when I am on Certification, I should see a sub-menu that shows:
My first thought, when I thought there only be 2 sub-menus, was to take the example here:
and then do 2 versions of that.
However, the client tells me they want to flexibility to create future pages with future sub-menus, so instead, I opened up:
vendor/bundle/ruby/2.0.0/bundler/gems/refinerycms-c8d8680bd4f5/pages/app/presenters/refinery/pages/
and I thought I might create a custom version of these methods:
def render_menu_items(menu_items)
puts " in render_menu_items"
if menu_items.present?
content_tag(list_tag, :class => list_tag_css) do
menu_items.each_with_index.inject(ActiveSupport::SafeBuffer.new) do |buffer, (item, index)|
buffer << render_menu_item(item, index)
end
end
end
end
def render_menu_item_link(menu_item)
link_to(menu_item.title, context.refinery.url_for(menu_item.url), :class => link_tag_css)
end
def render_menu_item(menu_item, index)
content_tag(list_item_tag, :class => menu_item_css(menu_item, index)) do
buffer = ActiveSupport::SafeBuffer.new
buffer << render_menu_item_link(menu_item)
buffer << render_menu_items(menu_item_children(menu_item))
buffer
end
end
I am wondering though, how do I query for just the sub-pages of 1 page?