phpzend-framework2breadcrumbsmicrodata

How can I add markup (such as microdata or a <div>) to Zf2 breadcrumbs?


I've constructed zf2 breadcrumbs for my application and it prints as expected:

<a href="main">main</a> > <a href="somthing-else">Something Else</a>

But what If I want to add some html tags? Is Javascript the only solution or there is ZF2 way?


Solution

  • You can define your custom partial for rendering by using $breadcrumb helper's setPartial() method.

    1. Create a breadcrumb.phtml file (application/partials/breadcrumb.phtml)
    2. In your partial;

      echo implode(', ', array_map(
          function ($item) { return '<span>'.$item->getLabel().'</span>' },
          $this->pages)
          );
      
    3. Use the helper like this:

      echo $this->navigation()
                ->breadcrumbs()
                ->setPartial('application/partials/breadcrumb');
      

    This functionality also documented here.