-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
knp_menu_render_breadcrumb function #24
Comments
@dbu @uwej11 Do you have an idea about the way this function could be implemented ? We need to find a way that let some flexibility for the user as they will want to customize the breadcumb look&feel a bit (for instance, some people will want a list, other will want a bunch of links with a One option I see is to use a BreadcumbRenderer for this, as it is in fact the same than the rendering: you get an item and you render it. The difference is the way you render it, which is precisely the job of the renderer. But this would mean the way to do this would be to use {{ knp_menu_render(menu, {'additional_path': ['Details' => '/post/42/details']}, 'breadcumb') }} instead of {{ knp_menu_breadcumb(menu, {'additional_path': ['Details' => '/post/42/details']}) }} as the later would mean assuming that a renderer has a special role and should be present (and would make it more difficult to replace the renderer without adding special stuff). What do you think about the proposal above ? Btw, adding additional items at the end of the breadcump is already supported by the library (and my proposal above uses the corresponding syntax): https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/MenuItem.php#L724 |
I think it's OK to solve it as you proposed - anything that is as easy to use as the menu rendering in templates should be fine. Just having the code as David mentioned is a bit awkward. |
Totally like this, good idea! ----- Reply message ----- @dbu @uwej11 Do you have an idea about the way this function could be implemented ? We need to find a way that let some flexibility for the user as they will want to customize the breadcumb look&feel a bit (for instance, some people will want a list, other will want a bunch of links with a One option I see is to use a BreadcumbRenderer for this, as it is in fact the same than the rendering: you get an item and you render it. The difference is the way you render it, which is precisely the job of the renderer. But this would mean the way to do this would be to use {{ knp_menu_render(menu, {'additional_path': ['Details' => '/post/42/details']}, 'breadcumb') }} instead of {{ knp_menu_breadcumb(menu, {'additional_path': ['Details' => '/post/42/details']}) }} as the later would mean assuming that a renderer has a special role and should be present (and would make it more difficult to replace the renderer without adding special stuff). What do you think about the proposal above ? Btw, adding additional items at the end of the breadcump is already supported by the library (and my proposal above uses the corresponding syntax): https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/MenuItem.php#L724 Reply to this email directly or view it on GitHub: |
In case of Twig Integration you can even use default TwigRenderer with custom template: {{ knp_menu_render(menu, { template: 'AcmeBundle::breadcrumb.html.twig' }) }} where "AcmeBundle::breadcrumb.html.twig" might look something like this: {% block compressed_root %}
{% spaceless %}
{{ block('root') }}
{% endspaceless %}
{% endblock %}
{% block root %}
{% set item = item.currentItem %}
{{ block('breadcrumb') -}}
{% endblock %}
{% block breadcrumb %}
{% if item %}
<ul class="breadcrumb">
{{ block('item') }}
<li class="active">{{ block('label') }}</li>
</ul>
{% endif %}
{% endblock %}
{% block item %}
{% if item.parent %}
{% set item = item.parent %}
{{ block('item') }}
<li><a href="{{ item.uri }}">{{ block('label') }}</a> <span class="divider">/</span></li>
{% endif %}
{% endblock %}
{% block label %}
{{ item.label }}
{% endblock %} |
it would be great to have a breadcrumb twig function similar to the knp_menu_render for the menu.
the function should expect either the menu name and then pick the currentItem based on the menu, or expect a MenuItem from which it builds the breadcrumb.
an additional cool feature would be to pass an optional array of titles and urls to append to the breadcrumb in case there is no menu item for the last entries in the breadcrumb (e.g. consider a menu item for an overview of postings and a breadcrumb on the details page of one posting. )
currently we have this code in twig to render a breadcrumb:
/cc @uwej711
The text was updated successfully, but these errors were encountered: