Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2 Breadcrumbs Helper - How to render it as an unordered list?

I'm new to Zend Framework2 and I´m asking for advice for the following situation:

I´m using the ZF2 Breadcrumbs Helper to create breadcrums on my project and this code:

 //breadcrumbs.phtml 

 echo $this->navigation('Navigation')
        ->breadcrumbs()
        ->setLinkLast(false)               // link last page
        ->setMaxDepth(7)                   // stop at level 7
        ->setMinDepth(0)                   // start at level 0
        ->setSeparator(' »' . PHP_EOL);    // separator with newline 

when rendered looks like this:

Home » Lorem Ipsum1 » Lorem Ipsum2 » Current Crumb

Exploring the source code:

<div id="breadcrumbs">
    <a href="/">Home</a>
    »
    <a href="/">Lorem Ipsum1</a>
    »
    <a href="/">Lorem Ipsum2</a>
    » Current Crumb
</div>

So, my question is: using the Breadcrumb Helper how can I get the following source code to be able to style the Breadcrumbs the way I want to?

<div id="breadcrumbs">
    <ul id="breadcrumbs">
       <li><a href="">Home</a></li>
       <li><a href="">Lorem Ipsum1</a></li>
       <li><a href="">Lorem Ipsum2</a></li>
       <li><a href="" class="current">Current Crumb</a></li>
    </ul>
</div>
like image 571
devanerd Avatar asked Nov 15 '12 16:11

devanerd


1 Answers

You can use the view helper to set a partial to use:

<?php $partial = array('application/navigation/breadcrumbs.phtml', 'default') ?>
<?php $this->navigation('navigation')->breadcrumbs()->setPartial($partial) ?>
<?php echo $this->navigation('navigation')->breadcrumbs()->render() ?>

And then your partial would be something like this (application/navigation/breadcrumbs.phtml):

<?php $container = $this->navigation()->breadcrumbs()  ?>
<?php /* @var $container \Zend\View\Helper\Navigation\Breadcrumbs */ ?>
<?php $navigation = $container->getContainer() ?>
<?php /* @var $navigation \Zend\Navigation\Navigation */ ?>

<ul class="breadcrumb">
    <li><a href="<?php echo $this->url('soemroute') ?>">Home</a> <span class="divider">/</span></li>
    <?php foreach($this->pages as $page): ?>
        <?php /* @var $page \Zend\Navigation\Page\Mvc */ ?>
        <?php if( ! $page->isActive()): ?>
            <li>
                <a href="<?php echo $page->getHref() ?>"><?php echo $page->getLabel() ?></a> 
                <span class="divider">/</span>
            </li>
        <?php else: ?>
            <li class="active">
                <?php if($container->getLinkLast()): ?><a href="<?php echo $page->getHref() ?>"><?php endif ?>
                <?php echo $page->getLabel() ?>
                <?php if($container->getLinkLast()): ?></a><?php endif ?>
            </li>
        <?php endif ?>
    <?php endforeach ?>
</ul>
like image 51
Andrew Avatar answered Oct 07 '22 11:10

Andrew