Drupal 7:如何创建不出现在站点导航中的菜单/路由项
如何在 Drupal 中创建不会自动呈现导航链接的新路线/菜单?
我正在尝试在 Drupal 中创建一个简单的页面回调,该回调不会显示在导航菜单中。
我有一个名为 helloworld
的模块。
.module
文件包含以下内容
function _helloword_page_callback()
{
return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
for following conventions.');
}
function helloworld_menu()
{
$items['helloworld'] = array(
'title' => 'Hello World',
'page callback' => '_helloword_page_callback',
'access arguments' => array('content'),
'type' => MENU_CALLBACK
);
return $items;
}
这成功地在网站上公开了 URL
http://example.drupal.com/helloworld
但是,尽管如此,我仍然在左侧 (Bartik) 导航菜单中收到一个链接那么
'type' => MENU_CALLBACK
,为什么这不起作用呢?我是否正确配置了菜单项?一个更可能的问题:我如何误解菜单类型常量/系统的使用?是否有额外的缓存需要清除而
drush cc all
无法处理?我还可以采取哪些其他步骤来调试此问题?
How can I create a new route/menu in Drupal that doesn't automatically render a navigation link?
I'm trying to create a simple page callback in Drupal that doesn't show up in the Navigation menu.
I have a module named helloworld
.
The .module
file contains the following
function _helloword_page_callback()
{
return array('#markup'=>'The quick brown fox says hello, and the lazy dogs thanks you
for following conventions.');
}
function helloworld_menu()
{
$items['helloworld'] = array(
'title' => 'Hello World',
'page callback' => '_helloword_page_callback',
'access arguments' => array('content'),
'type' => MENU_CALLBACK
);
return $items;
}
This successfully exposes a URL on the site of
http://example.drupal.com/helloworld
However, I'm still getting a link in the left hand (Bartik) navigation menu, despite the use of
'type' => MENU_CALLBACK
So, why isn't this working? Am I configuring the Menu item correctly? A more likely question: How am I misinterpreting the use of the menu type constants/system? Are there additional caches to clear that
drush cc all
wouldn't take care of? What other steps can I take to debug this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一定还有其他问题(也许您忘记清除缓存?),因为即使使用 Bartik,它也能按预期工作。在该示例中,导航中仅显示“Hello 2”:
顺便说一句,您的代码片段中存在拼写错误(
helloroute_menu
应命名为helloworld_menu
),但我假设这是由于在 StackOverflow 上发布之前进行了代码简化所致。There must be something else wrong (perhaps you forgot to clear the caches ?) because even with Bartik, it works as expected. In that example, only "Hello 2" is shown in the navigation:
By the way, there is a typo in your snipplet (
helloroute_menu
should be namedhelloworld_menu
), but I assume this is due to code simplification before posting on StackOverflow.查看菜单管理中的菜单链接。如果您在那里对其进行了自定义(例如重量更改),则即使您设置为回调类型,它也可能仍然存在。
如果是这种情况,您可以删除那里。
Check out that menu link in the menu administration. If you customized it there (weight change for example), it's possible that it remains even though you set to type to callback.
If that's the case, you can just delete there.