diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index e0db828dea..7cb2e3e136 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -180,6 +180,33 @@ def render_navigation(options = {}, html_options = {}) end deprecate render_navigation: 'Create a menu and use render_menu instead', deprecator: Alchemy::Deprecation + # Renders a menu partial + # + # Menu partials are placed in the `app/views/alchemy/menus` folder + # Use the `rails g alchemy:menus` generator to create the partials + # + # @param [String] - Name of the menu + # @param [Hash] - A set of options available in your menu partials + # @param [Hash] - A set of HTML options available in your menu partials + def render_menu(name, options = {}, html_options = {}) + root_node = Alchemy::Node.roots.find_by(name: name) + if root_node.nil? + warning("Menu with name #{name} not found!") + return + end + + options = { + node_partial_name: "#{root_node.view_folder_name}/node" + }.merge(options) + + render root_node, node: root_node, options: options, html_options: html_options + rescue ActionView::MissingTemplate => e + warning <<~WARN + Menu partial not found for #{name}. + #{e} + WARN + end + # Renders navigation the children and all siblings of the given page (standard is the current page). # # Use this helper if you want to render the subnavigation independent from the mainnavigation. I.E. to place it in a different area on your website. diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb index 3179502411..17d080b35d 100644 --- a/spec/dummy/app/views/layouts/application.html.erb +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -7,10 +7,10 @@ <%= csrf_meta_tags %>
+ <%= yield %> - <%= render "alchemy/edit_mode" %>