Is there a way to manage the navigation bar?
Opened this issue · 1 comments
karimmtarek commented
Currently the pages are added to the navigation based on when it was publish.
- Is there a way to decide which pages can be displayed?
- Is there a way to re-order the navigation links?
mekhovov commented
there is a way :)
create navigation, give it some handle
, add pages and reorder them:
inside app you can get that navigation by handle
main_navigation = Storytime::Navigation.find_by(handle: "main")
and then just render it:
render main_navigation
i have helper method that renders main navigation if it exists and all the pages in other case, also added admin page link if current user is admin
def render_main_menu
main_navigation = Storytime::Navigation.find_by(handle: "main")
menu_html = if main_navigation
render main_navigation
else
Storytime::Page.published.collect do |page|
content_tag :li do
link_to page.title, storytime.page_path(page)
end
end
end
if current_user&.admin?
menu_html << content_tag(:li) do
link_to t('defaults.admin'), storytime_admin_path
end
end
menu_html.html_safe
end
feel free to use it :)
i think that would be nice to include helper method like this to the core @bcroesch ?
in User model i have:
def roles
storytime_roles
end
def admin?
roles.pluck(:name).include? ('admin')
end