TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.96k stars 177 forks source link

How do I override the default breadcrumbs? #81

Closed x-ror closed 6 years ago

x-ror commented 6 years ago

I want add new hierarchy. Now it looks like this image But i want what's been like here. image How can I do this?

spohlenz commented 6 years ago

The default breadcrumbs in Trestle have this format:

Root Breadcrumb(s) / Current Admin / Current Action

If you wish to globally change the Root Breadcrumbs, you can edit your config/initializers/trestle.rb and add:

config.root_breadcrumbs = -> {
  [Trestle::Breadcrumb.new("label", "/path"), Trestle::Breadcrumb.new("label", "/path"), ...]
}

Within an admin, you can customize the Current Admin breadcrumb using:

Trestle.resource(...) do
  breadcrumb "label", "/path"
end

where the path parameter is optional.

If you want further control of the breadcrumbs within an admin, you can override the breadcrumbs method:

Trestle.resource(...) do
  admin do
    def breadcrumbs
      Trestle::Breadcrumb::Trail.new([
        Trestle::Breadcrumb.new("Label", "/path1"),
        Trestle::Breadcrumb.new("Label", "/path2")
      ])
    end
  end
end

To override the Custom Action breadcrumb, you will need to customize the show.html.erb template for your admin. Within the template, you can add calls to the breadcrumb(label, path) helper to append additional breadcrumbs.