在 drupal 主题中需要并放置块吗?
在我正在创建的主题中,我想将块放置在与默认位置不同的位置。例如,将搜索块放在标题中。
有没有办法从主题中做到这一点:能够要求一个块并将其放置在某个地方?
In a theme I'm creating I'm wanting to place blocks in locations that are different from the default ones. Eg place the search block in the header.
Is there any way to do this from a theme: Be able to require a block and place it somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Drupal 的主题系统足够灵活,可以将页面的该部分精确地转换为您希望块出现的区域。为此,您需要将区域添加到主题的
.info
文件中,如 将内容分配给区域,例如regions[foobar] = Foobar
。这将使新变量$page['foobar']
可用于您的 page.tpl.php。然后,您可以像使用 Drupal 的内置区域一样将内容分配给该区域。如果您想绕过此系统并临时显示块,请查看如何 _block_render_blocks 渲染块。
The theming system of Drupal is flexible enough to turn exactly that part of the page into a region where you want your block to appear. For this you need to add the region to the theme's
.info
file as described on Assigning contents to regions, e.gregions[foobar] = Foobar
. This will make a new variable$page['foobar']
available to your page.tpl.php. You can then assign content to the region the same way as with Drupal's builtin regions.If you want to circumvent this system and display a block ad-hoc, have a look at how _block_render_blocks renders blocks.
它击败了可配置块的想法,但仍然是可能的:您必须为除允许区域之外的所有区域创建空块模板。或者您为该块提供/覆盖主题函数,并且对于禁止区域不返回任何内容。
It defeats the idea of configurable blocks but nevertheless it's possible: You have to create empty block templates for all but the allowed region. Or you provide/override the theme function for this very block and return nothing for prohibited regions.
在 D7 中,您可以在主题 .info 文件中添加占位符区域,清除缓存并将块放入其中,然后可以输出该区域的内容。
In D7 you can add a placeholder region in your themes .info file, clear the cache and put your block in there you can then output the region's content.