Drupal 使用 Active Trail 属性创建动态菜单
我想创建一个动态菜单,该菜单将从特定节点类型获取其项目。我想我可以通过创建标题视图并将其放在一个块中来做到这一点。但是,当有人单击其中一个标题时,我想突出显示它,因此需要一种向链接添加活动类的方法。我知道 Drupal 会自动为菜单执行此操作,但我可以为基于视图的菜单执行此操作吗?
I want to create a dynamic menu that will get it's items from a certain node type. I thought I could do this by creating a view of the titles and putting it in a block. However, when someone clicks on one of these titles I want to highlight it, and so want a way of adding an active class to the link. I know Drupal does this automatically for menus, but can I do it for a menu based on a view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将安卓idea与hook_form_alter结合使用呢?像这样的事情会起作用:
假设您的内容类型称为“mycontent”:
在您的内容类型设置下,将允许的菜单父项设置为仅包含您想要的菜单,我们将其称为“自定义”。在模块文件中添加以下代码:
因此,$form_id 应等于“[my_content_type]_node_form”,父级的默认值应等于“menu-[my_menu]:0”
如果您担心用户不将其内容添加到菜单,这一行将夺走他们对表单项的控制:
why not use Andrews idea in conjunction with hook_form_alter? Something like this would work:
Assuming your content type is called "mycontent":
Under your content type settings set the allowed menu parents to only include the menu you want, we'll call it "custom". In your module file add the following code:
so, $form_id should equal "[my_content_type]_node_form", and the default value of parent should equal "menu-[my_menu]:0"
If you are concerned about users not adding their content to a menu, this line will take away their control of the form item:
我不太确定您对“动态菜单”的要求,但标题视图的替代方案可能是设置一个自定义菜单,然后当您创建这些节点时,将它们设置为该菜单的一部分节点编辑表单。然后在块中显示该菜单,您应该突出显示所需的活动项目。
I'm not real sure about your requirements for a "dynamic menu" but an alternative to the view-of-titles might be to set up a custom menu, then when you create these nodes, set them to be part of that menu in the node edit form. Then display that menu in the block And you should get the highlighting of active items you want.