2012-10-09 83 views
1

我一直在瘋狂地嘗試操縱我的主菜單的輸出與Twitter Bootstrap的下拉菜單兼容,我想知道如果有人在那裏做了類似的事情或有訣竅幫助我,並幫助我避免在這方面失去進一步的睡眠。正如例如引導程序菜單的我已經得到的東西,看起來像這樣:Drupal 6菜單輸出Twitter的引導

<ul class="nav"> 
    <li class="active"><a href="/">Home</a></li> 
    <li class=""><a href="/news">News</a></li> 
    <li class=""><a href="/sports">Sports</a></li> 
    <li class=""><a href="/opinion">Opinion</a></li> 
    <li class="dropdown"> 
     <a data-toggle="dropdown" class="dropdown-toggle" href="#">Special Sections <b class="caret"></b></a> 
     <ul class="dropdown-menu"> 
      <li><a href="/special/welcome">Welcome</a></li> 
      <li><a href="/special/orientation">Orientation</a></li> 
      <li><a href="/special/housing">Housing</a></li> 
     </ul> 
    </li> 
    <li class="dropdown"> 
     <a data-toggle="dropdown" class="dropdown-toggle" href="#">Media <b class="caret"></b></a> 
     <ul class="dropdown-menu"> 
      <li><a href="/media/video">Video</a></li> 
      <li><a href="/media/photo">Photo</a></li> 
     </ul> 
    </li> 
</ul> 

我所採用的主題掛鉤的嘗試:

<?php 
    print theme('links', $primary_links, array('id' => 'nav', 'class' => 'nav links primary-links')); 
?> 

隨着phptemplate_menu_itemphptemplate_menu_item_link功能的te​​mplate.php,但到目前爲止,我只能成功複製菜單的頂層。

作爲參考:Drupal Override Custom Menu Template

提前感謝!

回答

1

我可以通過調用自定義menu_tree函數來做到這一點:

print bootstrap_menu_tree('primary-links'); 

與這在我的主題的template.php文件:

function bootstrap_menu_tree($menu_name = 'navigation') { 
    static $menu_output = array(); 

    if (!isset($menu_output[$menu_name])) { 
    $tree = menu_tree_page_data($menu_name); 
    $menu_output[$menu_name] = bootstrap_menu_tree_output($tree); 
    } 
    return $menu_output[$menu_name]; 
} 

function bootstrap_menu_tree_output($tree, $dropdown_menu = false) { 
    $output = ''; 
    $items = array(); 

    // Pull out just the menu items we are going to render so that we 
    // get an accurate count for the first/last classes. 
    foreach ($tree as $data) { 
    if (!$data['link']['hidden']) { 
     $items[] = $data; 
    } 
    } 

    $num_items = count($items); 
    foreach ($items as $i => $data) { 
    $extra_class = array(); 
    if ($i == 0) { 
     $extra_class[] = 'first'; 
    } 
    if ($i == $num_items - 1) { 
     $extra_class[] = 'last'; 
    } 
    $extra_class = implode(' ', $extra_class); 
    if ($data['below']) { 
     $link = theme('menu_item_link', $data['link'], true); 
     $output .= theme('menu_item', $link, $data['link']['has_children'], bootstrap_menu_tree_output($data['below'], true), $data['link']['in_active_trail'], $extra_class); 
    } 
    else { 
     $link = theme('menu_item_link', $data['link']); 
     $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class); 
    } 
    } 
    return $output ? theme('menu_tree', $output, $dropdown_menu) : ''; 
} 





// theme_menu_tree() 
function phptemplate_menu_tree($tree, $dropdown_menu = false) { 
    $class = 'nav'; 
    if($dropdown_menu) $class = 'dropdown-menu'; 
    return '<ul class="'.$class.'">'. $tree .'</ul>'; 
} 

// theme_menu_item() 
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) { 
    $class = ($menu ? 'dropdown' : ($has_children ? 'dropdown' : '')); 
    if (!empty($extra_class)) { 
    $class .= ' '. $extra_class; 
    } 
    if ($in_active_trail) { 
    $class .= ' active-trail'; 
    } 
    return '<li class="'. $class .'">'. $link . $menu ."</li>\n"; 
} 

function phptemplate_menu_item_link($link, $dropdown_toggle = false) { 
    if (empty($link['localized_options'])) { 
    $link['localized_options'] = array(); 
    } 

    if($dropdown_toggle) { 
    // add class 
    if (isset($link['localized_options']['attributes']['class'])) { 
     $link['localized_options']['attributes']['class'] .= ' dropdown-toggle'; 
    } 
    else { 
     $link['localized_options']['attributes']['class'] = 'dropdown-toggle'; 
    } 
    // add toggle 
    $link['localized_options']['attributes']['data-toggle'] = 'dropdown'; 
    // add carat 
    $link['title'] .= '<b class="caret"></b>'; 
    $link['localized_options']['html'] = true; 
    } 

    return l($link['title'], $link['href'], $link['localized_options']); 
} 
+0

謝謝!我會在稍後嘗試,這看起來合法! – evancohen

+0

我正在尋找帶有多級菜單的引導式Drupal 6主題 - 您願意分享哪些作品? – key2starz