我在自定义Drupal 6模块中构建了一个标签式菜单.我想在我的模块页面顶部的选项卡式菜单右侧放置一个html下拉列表.该列表将在更改时触发一些ajax事件,例如通过指定10,20,50,100结果来更改SQL查询的LIMIT子句.如何在没有黑客模板的情况下在Drupal中实现这一目标?
谢谢,
你可以通过覆盖theme_menu_local_tasks()你的主题来做到这一点:
function yourTheme_menu_local_tasks() {
// Prepare empty dropdown to allow for unconditional addition to output below
$dropdown = '';
// Check if the dropdown should be added to this menu
$inject_dropdown = TRUE; // TODO: Add checking logic according to your needs, e.g. by inspecting the path via arg()
// Injection wanted?
if ($inject_dropdown) {
// Yes, build the dropdown using Forms API
$select = array(
'#type' => 'select',
'#title' => t('Number of results:'),
'#options' => array('10', '20', '50', '100'),
);
// Wrap rendered select in <li> tag to fit within the rest of the tabs list
$dropdown = '<li>' . drupal_render($select) . '</li>';
}
// NOTE: The following is just a copy of the default theme_menu_local_tasks(),
// with the addition of the (possibly empty) $dropdown variable output
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= "<ul class=\"tabs primary\">\n". $primary . $dropdown . "</ul>\n";
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
}
return $output;
}
Run Code Online (Sandbox Code Playgroud)
(注意:未经测试的代码 - 潜在的拼写错误)