ZF-7927: Add ability to wrap label during htmlify in Zend_View_Helper_Navigation_Menu

Description

The reason why I'd like to see the option to wrap the label with an element is because when a user is trying to style their navigation menu output with image sprites, currently, you would need JavaScript to remove the innerHTML from the element to hide the label.

Here's a link to the same technique I'm using on my sites: http://stylemeltdown.com/2007/10/…

Notice the element inside the element. This is an advantage because you can use CSS to hide the span and it still allows the content to be indexed and used with screen readers.

It would be nice to be able to specify an option which allows me to wrap the label. Specifically, it would be nice if I could just say {{array('labelWrapper' => 'span')}} or something much like that.

Comments

Assigning this issue to Robin Skoglund as he's the maintainer (and creator) of Zend_Navigation.

Robin, thoughts on this?

My thoughts: the rendering might be changed to some sort of decorators for ZF 2.0. This issue might be related to ZF-7003. Maybe I (or someone else) should create a wiki page for Zend_Navigation 2.0 to gather feedback and thoughts on changes/improvements.

Robin, thanks for the prompt response!

Decorators for 2.0 sounds like a great idea! That would give complete control of the output produced by the view helpers. I can dig it.

In the meantime, the output produced by view helper is sufficient for most use cases, however, in a situation when you want to apply background images to a link and hide the text, this is where it is limited. I think what I'm trying to ask for is a poor mans attempt at a decorator. However, this decorator only affects the label.

Another example could look like:

$this->navigation()->menu(null, array( 'labelWrapper' => array( 'element' => 'span', 'class' => 'label-span' ) );

That would then wrap the label with a span element and add the class of label-span. Any other options you supply would be translated to attribute on the wrapper element.

Just trying to brainstorm here. Maybe for now, I can simply write my own navigation menu view helper that add the ability, but I think we should discuss the idea of adding decorators of some sorts to the navigation view helpers in ZF 2.0.

Thanks!

I agree and also need an inner for styling purposes. I've tried using Javascript to inject spans inside of the anchors, but this breaks for non-JS browsers.

I've also tried providing my own view helper that extends Zend_View_Helper_Navigation_Menu to overload the htmlify() method, but my helper is not being picked up. I believe this is because the navigation helper adds its helper path to the end of the stack instead of the beginning. Since the helper paths are LIFO, it finds the built-in ZF helper instead of using mine.

I think we will wait for the implementation of rendering in Zend_Form 2.0 and then we adapt this for the navigation view helpers.

This is a task for version 2.5 or 3.