Skip to content

Instantly share code, notes, and snippets.

@smahi
Forked from Matho/refinerycms_submenu
Created February 21, 2014 22:28
Show Gist options
  • Save smahi/9144920 to your computer and use it in GitHub Desktop.
Save smahi/9144920 to your computer and use it in GitHub Desktop.
Refinery CMS 2.0.x
Rendering submenu - expanding 1 level deeper branch step-by-step
Example:
1)
- Home # Click here
- Contact
2)
- Home
-- Year # Click here
- Contact
3)
- Home
-- Year
--- 2012
--- 2011
--- 2010
- Contact
...
# views/refinery/_menu_branch.html.erb
<%
if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
# active is only 1 for submenu - currently opened branch title
classes << "active" if params[:path] == refinery.url_for(menu_branch.url)[1..-1]
css = "class='#{classes.join(' ')}'".html_safe
end
# if true, render selected branch to depth untill end
is_selected_branch = ( selected_page_or_descendant_page_selected?(local_assigns[:menu_branch]) ? true : false)
-%>
<li<%= ['', css].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to(menu_branch.title, refinery.url_for(menu_branch.url)) -%>
<% if (children = menu_branch.children unless hide_children).present? && is_selected_branch &&
(!local_assigns[:menu_levels] || menu_branch.ancestors.length < local_assigns[:menu_levels]) -%>
<ul class='clearfix'>
<%= render :partial => '/refinery/menu_branch', :collection => children,
:locals => {
:apply_css => local_assigns[:apply_css],
:hide_children => !!hide_children,
:menu_levels => local_assigns[:menu_levels]
} -%>
</ul>
<% end -%>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment