Skip to content

Instantly share code, notes, and snippets.

@michaelward82
Created August 18, 2011 22:33
Show Gist options
  • Save michaelward82/1155440 to your computer and use it in GitHub Desktop.
Save michaelward82/1155440 to your computer and use it in GitHub Desktop.
Limit menu rendering in Refinery CMS
<%
if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
css = "class='#{classes.join(' ')}'".html_safe
end
# dom_id DEPRECATED: REMOVE AT 1.1, serves no purpose same with css attributes 'first' and 'last'
dom_id = "id='item_#{menu_branch_counter}'".html_safe if menu_branch.parent_id.nil?
menu_levels = (RefinerySetting.find_or_set(:menu_sub_levels, '1') if menu_levels.nil?) - 1
-%>
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>
<% if ( (children = menu_branch.children unless hide_children).present? &&
menu_branch.ancestors.length <= menu_levels ) -%>
<ul class='clearfix'>
<%= render :partial => '/shared/menu_branch', :collection => children,
:locals => {
:apply_css => local_assigns[:apply_css],
:hide_children => !!hide_children
}
-%>
</ul>
<% end -%>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment