Opened 7 years ago
Last modified 6 years ago
#40872 new feature request
Add $item argument to start_lvl (nav menu walker)
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.7.5 |
Component: | Menus | Keywords: | reporter-feedback |
Focuses: | javascript, template | Cc: |
Description
Would it be possible to add the $item argument inside the start_lvl function?
Other than the usual dropdown menu, I'd also like to build megamenus and to make that possible, I need to use different ul tags (along with some JavaScript components). These custom ul tags will be different based on the parent li ((array) $item->classes) and $depth.
Change History (2)
#2
@
6 years ago
Normally, a custom walker can be like this:
public function start_lvl( &$output, $depth = 0, $args = array() ) { if ($this->has_children && $depth >= 1) { $output .= "{$indent}<div class='uk-navbar-dropdown'>{$n}"; $output .= "{$n}{$indent}<ul class='uk-nav uk-navbar-dropdown-nav'>{$n}"; } ... }
If we can also use the $item argument here, I could easily change the output.
if ( $this->has_children && $depth >= 1 && in_array( 'uk-columns', (array) $item->classes ) ) { $output .= "{$indent}<div class='uk-navbar-dropdown-grid'>{$n}"; ... }
I kept the code simply for easy understanding;
the original code is a bit more complex and not just about a different css class name (as the above example).
Right now, I was able to rely on jquery to unwrap/wrap code as a workaround but I prefer to do this inside the custom walker instead.
@mireillesan thanks for the feature request! Can you add some screenshots or pseudo code? It would go a long way in helping to get your idea across.