Skip to content
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

Open
dbu opened this issue Jan 10, 2012 · 4 comments

Comments

@dbu
Copy link
Collaborator

commented Jan 10, 2012

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:

{% set currentItem = knp_menu_get('main').currentItem %}
{% if currentItem %}
<div class="cmf-breadcrumb">
<ul>
    {% for title, url in currentItem.breadcrumbsArray %}
        <li><a href="{{url}}">{{ title }}</a></li>
    {% endfor %}
</ul>
</div>
{% endif %}

/cc @uwej711

@stof

This comment has been minimized.

Copy link
Collaborator

commented Feb 19, 2012

@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 / separator between them...). I don't really like the powerful option being to create a BreadcumbRendererInterface for this as it is totally overkill.

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

@uwej711

This comment has been minimized.

Copy link

commented Feb 20, 2012

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.

@dbu

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 20, 2012

Totally like this, good idea!

----- Reply message -----
Von: "Christophe Coevoet" reply@reply.github.com
An: "David" david@liip.ch
Betreff: [KnpMenu] knp_menu_render_breadcrumb function (#24)
Datum: So., Feb. 19, 2012 02:21

@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 / separator between them...). I don't really like the powerful option being to create a BreadcumbRendererInterface for this as it is totally overkill.

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:
#24 (comment)

@rybakit

This comment has been minimized.

Copy link

commented Feb 23, 2012

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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.