【发布时间】:2011-04-13 10:53:29
【问题描述】:
我正在开发一个模块,其中我的页面必须没有区域或额外内容。一种“请稍候”页面。
我如何禁用所有额外的内容(区域菜单...等)?我认为 Panels 有这种能力,但我找不到它使用的 sn-p。
另一方面,模块是否可以指定特殊的自定义页面?比如维护页面?
【问题讨论】:
标签: drupal drupal-modules drupal-theming
我正在开发一个模块,其中我的页面必须没有区域或额外内容。一种“请稍候”页面。
我如何禁用所有额外的内容(区域菜单...等)?我认为 Panels 有这种能力,但我找不到它使用的 sn-p。
另一方面,模块是否可以指定特殊的自定义页面?比如维护页面?
【问题讨论】:
标签: drupal drupal-modules drupal-theming
page.tpl.php 方法不灵活。它基于表示逻辑。您应该将 hook_page_alter() 用于业务逻辑解决方案。例如:
function yourmodulename_page_alter(&$page) {
if (current_path() == 'node/add/yourcontenttype') {
unset($page['sidebar_first']);
}
}
还要看很厉害的Context module。
【讨论】:
您可以专门为要隐藏区域的页面创建一个额外的 page.tpl.php。命名原则类似于节点的命名原则。
假设您有一个 URL 为 example.com/content/contact 的页面。一个名为 page--content--contact.tpl.php 的模板将提供该页面以及以该 url 开头的任何页面,即页面 example.com/content/contact/staff 也将使用该模板(我认为)。
检查 body 元素的类以获取可以为模板命名的线索,大多数主题都会打印出来。在我上面的示例中,body 元素将包含 page-content-contact 类。
【讨论】:
我唯一能想到的就是在你的 page.tpl.php 文件中写检查,看看你是否在那个“页面”上你正在谈论而不是打印出区域/菜单,或者使用不同的模板。 http://drupal.org/node/223440
【讨论】:
如果你想这样做之前块被渲染:
/**
* Implements hook_block_list_alter()
*
* Hides the right sidebar on some pages.
*/
function THEME_NAME_block_list_alter(&$blocks) {
// This condition could be more interesting.
if (current_path() !== 'node/add/yourcontenttype') {
return;
}
// Go through all blocks, and hide those in the 'sidebar_second' region.
foreach ($blocks as $i => $block) {
if ('sidebar_second' === $block->region) {
// Hide this block.
unset($blocks[$i]);
}
}
}
注意:有趣的是,无论您是在主题中还是在模块中,这个钩子似乎都有效。 (如有错误请指正)
【讨论】: