menu_menu_link를 사용하여 메뉴를 수정합니다 (이 경우에는 main_menu). Evertything은 예상대로 작동하지만 메뉴 블록을 사용하여 내부 페이지의 사이드 바에있는 기본 메뉴의 다른 인스턴스를 렌더링합니다.Drupal - them_menu_link를 사용하여 메뉴 인스턴스를 하나만 수정하는 방법
문제는 사이드 바에서 사용하고있는 인스턴스가 아니라 사이트의 기본 탐색에 사용하는 main_menu의 인스턴스에만 내 수정 사항이 표시되기를 원합니다.
세부 사항 :
여기 내 theme_menu_link 기능
/**
* Returns custom HTML for the main navigation menu.
* Adds an HTML element to top level parent <li> elements
* to serve as a drop-down menu toggle.
*
* this also sets the HTML wrapper for sub menus, to override the above
* them_menu_tree function, which is intended for top level menus only.
*
* @param $variables
* An associative array containing:
* - element: Structured array data for a menu link.
*
* @ingroup themeable
*/
function mytheme_menu_link__main_menu($variables) {
$element = $variables['element'];
$child_menu = $element['#below'];
$sub_menu = '';
// if the current top level item has child menus (sub menus)
if ($child_menu) {
// unset the sub menu wrapper set above in mytheme_menu_tree__new_main_menu()
unset($child_menu['#theme_wrappers']);
// add opening ul tag for the sub menu wrapper to $sub_menu
$sub_menu = '<ul class="menu sub-menu">';
// iterate over each sub menu item
foreach ($child_menu as $child_menu_item){
// add sub menu item link HTML to a variable
$child_menu_output = l($child_menu_item['#title'], $child_menu_item['#href']);
// check to see if item has a title, sincle $element['#below'] returns things besides menu items
if($child_menu_item['#title']) {
// output each sub menu item's link and description, wrapped in a <li> element
$sub_menu .= '<li>' . $child_menu_output .'</li>';
} // end if shild menu item has a title
} // end foreach child menu item
// add closing ul tag for the sub menu wrapper to $sub_menu
$sub_menu .= '</ul>';
}
// output a dummy link for top level items
$output = '<a href="#" class="nolink">' . $element['#title'] . '</a>';
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . '</li>';
}
위의 함수가 나는 그것이 사이트의 기본 탐색 작업 할 것처럼 작동합니다. 그러나, 메뉴 모음과 함께 사이드 바에서 사용하고있는 main_menu의 인스턴스에 적용하지 않기를 바랍니다. 거기에 조건에 따라 them_menu_link를 조건부로 사용하는 방법이 있나요? 아니면 메뉴가 빙에 렌더링 되었습니까?
이 메뉴는 당신을 위해 일을 속성하지 않는 이유는 무엇입니까? https://www.drupal.org/project/menu_attributes – hyunkeln
나는 그 모듈을 보았지만, 내가하려고하는 것을 다루지 않는 것 같다. 메뉴 항목 속성뿐만 아니라 메뉴 마크 업을 커스터마이징한다. 특정 메뉴의 단일 인스턴스에 대한 사용자 정의 내 대답은 아래 작품. –