0

I have a menu section in my theme where i display the main-menu menu. This works as expected. with the following code.

<?php print theme('links', array(
                    'links'         => menu_navigation_links('main-menu'), 
                    'attributes'    => array('class'=> array('navbar', 'navbar-collapse', 'collapse')) 
));?>

I would like to make a block region inside of this rendered menu section for the search box. The end results will be block region at the end of the menu that i can style to be to the right of the menu. I could do this in css but was hoping to make the rendered html a little cleaner. This is what I have tried.

<?php print theme('links', array(
                'links'         => menu_navigation_links('main-menu'), 
                'attributes'    => array('class'=> array('navbar', 'navbar-collapse', 'collapse')) ,
                'region'        => render($page['search']);
));?>

There looks to be no tutorials on adding a block region to the menu array. Is is possible to inject a block region into the menu render array?

1

Part of the problem is that regions aren't really what you're looking for here. Drupal regions are just areas of the page, and you set content to appear in a given region. One way of utilizing regions for this would be to have a menu region defined in your theme's .info file, and then putting the menu and the search block in that region. I'm betting that's not really what you're after, though, because it doesn't result in very clean code.

There are two other options that I can see. One is to create your own theme callback for menus so that instead of calling theme('links', array(...)), you're calling theme('your_new_theme_callback', array(...)). You can define different variables for this theme, and one of them could be for the search block.

Of course, because this is Drupal, there's already someone who's gone "Man, I really want blocks in my menu and there's no nice way to do that in Drupal" and created a module. The Menu Attach Block module lets you attach a block to your menu. I've not used it before so I'm not 100% sure how to implement it in the way you're looking for. It doesn't look like you'd have to change your code at all, I don't think, because it looks like the module overrides theme_link() for you.

Does that make sense? If you want more details, let me know!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.