Breadcrumbs for custom routes¶
To configure breadcrumbs for a custom route you need to configure
1 2 3 4 5 6
breadcrumb_names must be configured for the breadcrumbs to render correctly.
||Valid route identifier which exists in at least one of the routing YAML files.|
||Name for the breadcrumb element. If the translation is not set, there will be a fallback to route translation.In the example above if the
If you want breadcrumbs to have more than one part, you can specify more paths and names with the
breadcrumb_names must contain two parts.
In the example below breadcrumbs are generated with two elements (Profile and Blog list):
1 2 3 4 5 6
Restricting HTTP methods
When using breadcrumbs for custom routes you cannot restrict the HTTP method for the controller in the routing file.
To see the correct breadcrumb, you have to check the method in the controller itself:
1 2 3
Custom breadcrumb generator¶
To create a custom breadcrumb generator you have to write a generator class and register it as a service tagged as
The generator must implement
BreadcrumbsGeneratorInterface and its two methods.
You can use
which implements this interface and provides access to the WhiteOctober breadcrumbs library.
Every breadcrumb generator has to add a
translationParameters array with
Always create all three keys and leave the elements empty if not needed.
If you can't or do not want to use
renderBreadcrumbs() method must handle rendering the HTML code for the breadcrumbs.
The highest priority generator which matches
canRender() renders the breadcrumbs for the current request.