2012-10-09 2 views
1

내 기본 메뉴의 출력을 조작하여 트위터 부트 스트랩의 드롭 다운 메뉴와 호환되도록 노력하고 있으며, 그 밖의 사람이 비슷한 것을했는지 궁금합니다. 나를 도우려는 노하우가 있고 이것에 대한 더 많은 수면을 잃지 않게 해줍니다. , template.php에Twitter의 부트 스트랩을위한 Drupal 6 메뉴 출력

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

phptemplate_menu_item_link 기능 : 나는 테마 후크를 사용하려고했습니다

<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> 

: 그냥 부트 스트랩 메뉴의 예로서 나는이처럼 보이는 뭔가있어 그러나 지금까지는 메뉴의 최상위 수준 만 성공적으로 복제 할 수있었습니다. 참고로

: 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

관련 문제