简体   繁体   English

Drupal中的动态块

[英]Dynamic block in Drupal

I have a couple of node types, policy, quote, customer etc and each of those has a set of actions called that are printed in a menu of links which are coded into the template file. 我有几个节点类型,策略,报价,客户等,每个节点都有一组称为的动作,这些动作被打印在链接菜单中,这些链接被编码到模板文件中。 I want to put this menu into a block so that I can reposition it, so the block needs to be dynamic. 我想将此菜单放入一个块中,以便可以重新放置它,因此该块需要动态。

I was going to just create a block in a module, and in the $block['content'] just foreach out an array of actions...but I can't find out how to firstly make those variables available to the block and secondly where to do so. 我本来只是在模块中创建一个块,然后在$ block ['content']中仅提出一系列动作...但是我不知道如何首先使这些变量可用于该块并其次在哪里做。

I looked at preprocess functions but I could only make out that they are for passing variables to the template rather than to a block. 我看了预处理功能,但我只能确定它们是用于将变量传递给模板而不是块的。 Does anyone have any suggestions here, otherwise it seems that blocks are just completely isolated? 有人在这里有什么建议吗,否则似乎块是完全隔离的吗?

The only other way I thought to do it would be to get the node Id from the arg() and load it, then a switch statement depending on the node type to add the actions - but that seems like a very messy and roundabout way to do it, especially when adding node types int eh future. 我想做的唯一另一种方法是从arg()获取节点ID并加载它,然后根据节点类型添加一个switch语句以添加操作-但这似乎是一种非常凌乱且round回的方式做到这一点,尤其是在将来添加节点类型时。

You probably want to use panels to provide these "panes". 您可能希望使用面板来提供这些“窗格”。

You can render your nodes in "full content mode" in a pane on a panel and they will automatically get your links from the tpl and you gain alot more power over their selective display, context and relationship to the other content on the page. 您可以在面板上的窗格中以“完整内容模式”呈现节点,它们将自动从tpl获取链接,并且通过其选择性显示,上下文以及与页面上其他内容的关系,您将获得更多的权力。

Drupal 8 is going the ctools panels route so its worth your time to spend a minute to learn. Drupal 8正在使用Ctools Panel,因此值得您花一些时间来学习。 Please feel free to ask any questions you have about 请随时问您任何有关的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM