我有一个模块,添加一个链接到主菜单。当我单击该链接时,请求的页面将被加载(一个.js和.html文件)。
我的主菜单是这样的:
我的代码如下所示:
<?php
/**
* Implements hook_menu()
*/
function kl_menu(){
$items = array();
$items['simple_link'] = array(
'title' => t('my link'),
'page callback' => 'build_page',
'access arguments' => array('access content'),
'menu_name' => 'main-menu',
'type' => MENU_NORMAL_ITEM,
);
/*
* build_page
*/
function build_page() {
drupal_add_js(drupal_get_path('module', 'kl') . '/mypage.js', 'file');
return ( file_get_contents( drupal_get_path('module', 'kl').'/mypage.html') );
}现在,我想添加一个子菜单,而不是一个简单的普通链接,这样我的主菜单看起来就像这样:
我想当我点击“我的子菜单”,然后这个子菜单展开显示更多的链接。然后,当我再次点击我的子菜单,我希望它崩溃。
我对drupal非常陌生,等等。
我怎么能做到。我用的是花环主题。
谢谢
爸爸
发布于 2013-02-26 05:19:56
/**
* Implements hook_menu().
*/
function kl_menu() {
$items['simple_link'] = array(
'title' => t('my link'),
'page callback' => 'kl_build_page',
'access arguments' => array('access content'),
'menu_name' => 'main-menu',
'type' => MENU_NORMAL_ITEM,
);
$items['simple_link/my_sublink_1'] = array(
'title' => t('my sub link 1'),
'page callback' => 'mymodule_sub_page_1',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['simple_link/my_sublink_2'] = array(
'title' => t('my sub link 2'),
'page callback' => 'mymodule_sub_page_1',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_theme().
*/
function kl_theme() {
$template_path = drupal_get_path('module', 'kl') . '/templates';
return array(
// File would be <module path>/templates/kl-build-page.tpl.php
'kl_build_page' => array(
'path' => $template_path,
'template' => 'kl-build-page')
),
// File would be <module path>/templates/kl-sub-page-1.tpl.php
'sub_page_1' => array(
'path' => $template_path,
'template' => 'kl-sub-page-1')
),
// File would be <module path>/templates/kl-sub-page-2.tpl.php
'sub_page_2' => array(
'path' => $template_path,
'template' => 'kl-sub-page-2')
),
);
}
/**
* Callback for main build page.
*/
function kl_build_page() {
drupal_add_js(drupal_get_path('module', 'kl') . '/mypage.js', 'file');
return theme('kl_build_page');
}
/**
* Page callback for sub page 1
*/
function kl_sub_page_1() {
return theme('kl_sub_page_1');
}
/**
* Page callback for sub page 2
*/
function kl_sub_page_2() {
return theme('kl_sub_page_2');
}https://stackoverflow.com/questions/15080452
复制相似问题