Hi all,

I am developing a theme from fusion_core and facing a problem with the main menu (ie. the top menu). Right now it has 2 main items, one is Shopping and another is Services. In Services, there are 2 other items, one is Mobile and another is Cash. I'm using the following code in the file page.tpl.php to print the main menu.

print theme('links__system_main_menu', array(
    'links' => $main_menu,
    'attributes' => array(
        'id' => 'gwt-main-menu',
        'class' => 'hidenav',
	'role' => 'menu',
	'heading' => array(
            'text' => t('Main menu'),
            'level' => 'h2',
            'class' => array('element-invisible'),

What I expect are

- The main menu items must be displayed on one-row only.
- The main menu item Services must be displayed like a drop-down menu and will show its sub menu items (ie. the Mobile and Cash menu items) only when user moves mouse to it.

In other words, it must be something like this

<ul role="menu" class="hide nav" id="gwt-main-menu">
	<li class="dropdown active" id="mnu-shopping">
		<a target="_self" href="/shopping/catalog">Shopping</a>
	<li class="dropdown" id="mnu-service">
		<a target="_self" href="service">Services <b class="caret"></b></a>
		<ul class="dropdown-menu " role="menu">
			<li id="mnu-service-airtime">
				<a target="_self" href="/service/mobile">Mobile</a>
			<li id="mnu-service-cashadv">
				<a target="_self" href="/service/cashadv">Cash</a>

However, when testing, I saw the main menu items are listed vertically in many rows (in this case 2 rows). Not only that, the main menu item Services does not display like a dropdown menu. When I viewed source, this is what I got.

Can someone please tell me what do I need to do to achieve the expectations above? I searched on the Internet but the posts I found don't help me at all. Although they all agree that I should override the functions in the file template.php, but they don't give me enough instructions of what I need to do or how I start. I'm new in themeing drupal 7. Please help! Thanks.


VM’s picture

why printing the menu manually? You can enable the menu block in a region. see: administer -> blocks

According to the fusion project page:

Superfish dropdown menus can be enabled by selecting "Expanded" next to the parent menu item in your menu configuration

You don't mention selecting the "Expanded" setting.

H-J’s picture

VM are we multi-threading topics now?

Drupal is really GREAT!!

VM’s picture

I'm not sure what you are asking me.

H-J’s picture

I saw another thread that has the exact same topic from the exact same person

VM’s picture

ok so what exactly is your point? That i missed a duplicate post? if so; it happens.

H-J’s picture

No.. *sigh* You know what just forget it.. Focus on helping people... Sorry for distracting your work.

drupal_dev_2014’s picture

sorry yesterday the web page was freezing and kept throwing the error message 502 (ie. "bad gateway") to my face, so I pressed the F5 many times. May be that's why there are many duplicate posts. If you are admin, please delete other duplicate posts for me. Thanks.

drupal_dev_2014’s picture

This is the requirement for the project of my company. Apparently they don't want to enable and/or format the main menu through Structure > Menus or Structure > Blocks. They want the menu displays automatically when the page is loaded. By the way, Superfish is not what they want. They only trust fusion and that's that. I have to build the whole theme from fusion_starter. This is the guideline that they expect me to follow.... https://drupal.org/node/629454

VM’s picture

This is the requirement for the project of my company. Apparently they don't want to enable and/or format the main menu through Structure > Menus or Structure > Blocks. They want the menu displays automatically when the page is loaded

That's an odd explanation of a requirement as blocks are loaded when the page is loaded.

By the way, Superfish is not what they want. They only trust fusion and that's that.

There are no drop down menus in drupal by default. Fusion uses superfish for that feature as stated on the project page for the theme in use. That's what fusion provides. Else you can write your own custom module.

drupal_dev_2014’s picture

My company indeed require me to write some custom code in order to display the main menu and all of its items (even child nodes). This is my current code in the file template.php. Would you please help me how to get each menu's child items and display them when user hovers mouse to it?

function mca_links__system_main_menu($variables){

	/*print "<script>window.alert('calling the mca_links__system_main_menu function')</script>";//this message is for testing only		*/	

  $links = $variables['links'];
  $attributes = $variables['attributes'];
  $heading = $variables['heading'];
  global $language_url;
  $output = '';
  //echo count($links);

  if (count($links) > 0) {
    $output = '';

    // Treat the heading first if it is present to prepend it to the
    // list of links.
    if (!empty($heading)) {
      if (is_string($heading)) {
        // Prepare the array that will be used when the passed heading
        // is a string.
        $heading = array(
          'text' => $heading,
          // Set the default level of the heading.
          'level' => 'h2',
      $output .= '<' . $heading['level'];
      if (!empty($heading['class'])) {
        $output .= drupal_attributes(array('class' => $heading['class']));
      $output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
	//print $output;
    $output .= '<ul' . drupal_attributes($attributes) . '>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $link) {
      //$class = array($key);
	$class = array();
	echo "<script>window.alert(".$link['href'].");</script>";
	$class[] = 'dropdown';

      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
          && (empty($link['language']) || $link['language']->language == $language_url->language)) {
        $class[] = 'active';
      $output .= '<li' . drupal_attributes(array('class' => $class)) . '>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
//		$output .= "<a href="{$link['href']}">{$link['title']}</a>";
      elseif (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes.
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        $output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';

      $output .= "</li>\n";

    $output .= '</ul>';

//print $output;
  return $output;

By the way, do you know how to add a unique id in every menu item?

For example:
Shopping ----> id: mnu-shopping
Services ----> id: mnu-service

This's also a requirement for the project.

Thanks y'all.

VM’s picture

dropdowns = look at an already existing module for aid with code for implementation

unique id's = https://drupal.org/node/345624

drupal_dev_2014’s picture

Thanks. This works

drupal_dev_2014’s picture

ok now I've managed to get the menu to display horizontally in one line. Now I'm facing the 2nd issue. How can I get the list of the items of the menu Services and display them all when user move mouse to the menu Services?

streever’s picture

This is not my place, really, but I have to ask:
your company "only trusts fusion", but they trust the custom code of someone writing a drop-down as they learns how?

Superfish is an excellent module, written and then edited by potentially hundreds of people, and passing QA checks from tens of thousands.

It seems very odd to me that you are writing your own version of superfish by hand and they are OK with that, but they refuse to use superfish as a "trust" issue?

I provide free Drupal support on Thursdays: booking calendar coming soon.

drupal_dev_2014’s picture

yes you get that right. My company doesn't really trust Superfish and want to build their own theme from scratch. That's why I have to write all these custom code. I hope you guys don't mind helping me. I'm not very good in theme development, to be honest. I only know how to download already-built themes and modules and use them. I've never built a whole theme from scratch like this before.

VM’s picture

you're essentially going to have to write the code on your own. The javascript for the dropdowns and the module to integrate the javascript with the menu items. Which is pretty silly considering there is already multiple modules in contrib that produce this feature.

drupal_dev_2014’s picture

fortunately they at least allow me to use the already-built js and css files from their previously-built system in jsp. That reduced about 10% of my workload. Otherwise my head would be exploded (*sigh*)

Anyway now my menu seems to display correctly as required, but I'm facing another issue. Please refer to my latest thread https://drupal.org/node/2087227. Thanks.

drupal_dev_2014’s picture

Some companies indeed demand more than just work performance. They are too extreme in loving creativity. They worship it. They reject using the already-built applications. They rarely use open source. They just want to build everything from scratch. That sounds silly, but true. (*sigh*)