简体   繁体   English

如何从finerycms菜单中删除特定的引擎页面和引擎菜单项?

[英]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. 我已经在finerycms中创建了一个引擎,将数据拉到主页上。 Refinerycms automatically creates a page and a menu item for this engine. Refinerycms自动为此引擎创建一个页面和一个菜单项。

How can i delete the engine page as well as remove it from my menu bar? 如何删除引擎页面以及将其从菜单栏中删除?

menu.html.erb 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 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" 我要从菜单栏中删除的菜单项特别是“新程序”

The easiest way do to this is to remove the page from the console : 最简单的方法是从控制台中删除页面:

  • Enter in the rails console : bundle exec rails c 在rails控制台中输入: bundle exec rails c
  • Find the page you want to delete : page = Refinery::Page.find("your-page-id") 找到您要删除的page = Refinery::Page.find("your-page-id")page = Refinery::Page.find("your-page-id")
  • Destroy it : page.destroy! 销毁它: 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. 请注意,“ your-page-id”应替换为页面的ID;),当您在前端或后端访问此页面时,可以在URL中看到它。

Also we use the destroy! 我们也使用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. 最后,您可以通过编辑引擎的种子文件来阻止创建此页面。

我终于发现,如果您单击Refinerycms在Refinerycms中编辑页面,则存在一个复选框,用于确定是否将该页面包含在公共菜单中。

您还可以在生成引擎时添加skip-frontend选项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM