Zend Framework

Add ability to wrap label during htmlify in Zend_View_Helper_Navigation_Menu

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.2
  • Fix Version/s: None
  • Component/s: Zend_View
  • Labels:
    None

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 <a> element to hide the label.

Here's a link to the same technique I'm using on my sites: http://stylemeltdown.com/2007/10/22/image-sprite-navigation-with-css/

Notice the <span> element inside the <a> 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.

Activity

Hide
Dolf Schimmel (Freeaqingme) added a comment -

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

Show
Dolf Schimmel (Freeaqingme) added a comment - Assigning this issue to Robin Skoglund as he's the maintainer (and creator) of Zend_Navigation.
Hide
Joe Gornick added a comment -

Robin, thoughts on this?

Show
Joe Gornick added a comment - Robin, thoughts on this?
Hide
Robin Skoglund added a comment -

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.

Show
Robin Skoglund added a comment - 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.
Hide
Joe Gornick added a comment -

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!

Show
Joe Gornick added a comment - 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!
Hide
Hector Virgen added a comment -

I agree and also need an inner <span> 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.

Show
Hector Virgen added a comment - I agree and also need an inner <span> 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.

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated: