Catfish
Catfish

Reputation: 19312

How to remove specific engine page and engine menu item from refinerycms menu?

I've created an engine in refinerycms where i'm pulling the data onto the homepage. Refinerycms automatically creates a page and a menu item for this engine.

How can i delete the engine page as well as remove it from my menu bar?

menu.html.erb

<%
  # Collect the root items.
  # ::Refinery::Menu is smart enough to remember all of the items in the original collection.
  if (roots = local_assigns[:roots] || (collection ||= refinery_menu_pages).roots).present?
    dom_id ||= 'menu'
    css = [(css || 'menu clearfix')].flatten.join(' ')
    hide_children = Refinery::Core.menu_hide_children if hide_children.nil?
-%>
<div id="nav">
  <ul>
    <%= render :partial => '/refinery/menu_branch', :collection => roots,
               :locals => {
                 :hide_children => hide_children,
                 :sibling_count => (roots.length - 1),
                 :menu_levels => local_assigns[:menu_levels],
                 :apply_css => true #if you don't care about class='first' class='last' or class='selected' set apply_css to false for speed.
               } -%>
  </ul>
</div>

<% end -%>

menu_branch.html.erb

<%
  if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
    css = "class='#{classes.join(' ')}'".html_safe
  end
-%>
<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? &&
          (!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>

The menu item in particular that i want removed from the menu bar is "new programs"

Upvotes: 0

Views: 2219

Answers (3)

secador de pelo
secador de pelo

Reputation: 709

You could also add the skip-frontend option when generating the engine:

rails generate refinery:engine NAME [field:type field:type] --skip-frontend

Upvotes: 3

Catfish
Catfish

Reputation: 19312

I finally found that when editing a page in Refinerycms if you click advanced options, there is a checkbox on whether to include the page in the public menu or not.

Upvotes: 4

Adrien Coquio
Adrien Coquio

Reputation: 4930

The easiest way do to this is to remove the page from the console :

  • Enter in the rails console : bundle exec rails c
  • Find the page you want to delete : page = Refinery::Page.find("your-page-id")
  • Destroy it : page.destroy!

Notice that "your-page-id" should be replace by the id of your page ;), you can see it in the URL when you access this page in the frontend or backend.

Also we use the destroy! method because, by default, this page is set to undeletable.

Finally, you can prevent the creation of this page by editing the seeds file of your engine.

Upvotes: 7

Related Questions