【问题标题】:Why doesn't this code work to check if a region is occupied?为什么这段代码不能检查一个区域是否被占用?
【发布时间】:2012-02-07 20:36:56
【问题描述】:

我的主题中有以下代码来检测leftsidebar 区域中是否存在块。问题是这个 HTML 代码仍然会在leftsidebar 区域中没有块的页面上得到输出。我完全不知道问题是什么。我对其他块执行相同的代码并且它可以工作。

这是我的 page.tpl.php 文件中的代码...

<?php if (!$page['sidebar']): ?>
<div id="content-area" class="one-col">
<?php endif; ?> 

<?php if ($page['sidebar'] && !$page['leftsidebar']): ?>
<div id="content-area" class="two-col">
<?php endif; ?> 

<?php if ($page['leftsidebar']): ?>
<div id="content-area" class="three-col">
<?php endif; ?> 

这是我的 .info 文件中的块区域...

regions[leftsidebar] = Left Sidebar

【问题讨论】:

    标签: php drupal drupal-7 drupal-blocks


    【解决方案1】:

    只需检查&lt;?php if($leftsidebar): ?&gt;。然后添加所有标记。

    【讨论】:

    • 我试过了,还是不行。我相信这是签入 Drupal 6 的方法。我正在使用 7。
    • 试试这样的:&lt;?php if ($page['sidebar_first']): ?&gt; &lt;?php print render($page['sidebar_first']); ?&gt; &lt;?php endif; ?&gt;
    • 嗯.. 有效。想知道为什么?我总是像这样打印我的块区域...&lt;?php print render($page['headerimage']); ?&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 2016-04-14
    • 2012-07-06
    相关资源
    最近更新 更多