cnerta/breadcrumb-bundle

This bundle provides a breadcrumb for the KnpMenu library

Installs: 11 544

Dependents: 0

Stars: 10

Watchers: 4

Forks: 3

Open Issues: 1

Language: PHP

2.0.1 2014-08-26 10:09 UTC

README

The CnertaBreadcrumbBundle provide an easy way to create a breadcrumb with KnpMenuBundle for Symfony2

SensioLabsInsight

Build Status Latest Stable Version Latest Unstable Version

Install the Bundle

  1. Add the sources in your composer.json
     "require": {
        // ...
        "cnerta/breadcrumb-bundle": "2.0.*"
    }
  1. Then add it to your AppKernel class::
    // in AppKernel::registerBundles()
    $bundles = array(
        // ...
        new Cnerta\BreadcrumbBundle\CnertaBreadcrumbBundle(),
        // ...
    );

Default configuration

You don't have to configure anything. This part is only usefull if you want to setup a default breadcrumb template.

config.yml

    cnerta_breadcrumb:
        twig:
            template: CnertaBreadcrumbBundle::cnerta_breadcrumb.html.twig

Rendering Breadcrumb

First create your menu with the KnpMenuBundle.

Next, in your twig template call :

    {{ cnerta_breadcrumb_render('MyWonderfullBundle:Builder:Menu') }}

Or if you just want to get the breadcrumb array and make your stuff :

    {% set currentItem = cnerta_breadcrumb_get('MyWonderfullBundle:Builder:Menu') %}
    {# some crasy stuff #}
    {% for item in currentItem %}
        {% if loop.index != 1 %}
            {% if loop.index > 1 %} > {% endif %}
            {% if not loop.last %}<a href="{{ item.uri }}">{{ item.label }}</a>
            {% else %}<span>{{ item.label }}</span>{% endif %}
        {% endif %}
    {% endfor %}

If you want to use your own template for rendering :

    {{ cnerta_breadcrumb_render('MyWonderfullBundle:Builder:Menu', {'template': 'MyWonderfullBundle:Breadcrumb:myBreadcrumb.html.twig'}) }}

Unit test the Bundle

Before running phpunit you must load dependencies. This will only load the required vendors needed for run test.

     composer install --dev

After that you can run phpunit.

      phpunit -c phpunit.xml.dist