doumao1047
2012-04-26 13:03 阅读 54
已采纳

我的PHP条件语句显示if和else的两个结果,我的代码有什么问题?

I created a conditional statement for my custom theme in Concrete5. My codes goal is to toggle layout. If the current page has a child pages under it, it will display an additional sidebar (<div class="grid_3">) to list the subpages items. If there's no child page it would display a full layout (<div class="grid_13">).

Unfortunately I get a different result. there's something I probably had missed on my condition statement. Instead of just display one layout, It is rendering the two layout.

Below is what my code look like:

<? if($c->getNumChildren()) { ?>


<div class="grid_3">
    <?php   
    $bt_sidenav = BlockType::getByHandle('autonav');
    $bt_sidenav->controller->orderBy = 'display_asc';
    $bt_sidenav->controller->displayPages = 'below';
    $bt_sidenav->controller->displaySubPages = 'all';
    $bt_sidenav->render('view');
    ?>
</div>

<div id="main-content-container" class="grid_10">
    <div id="main-content-inner">
        <?php
        $a = new Area('Main');
        $a->display($c);
        ?>          
    </div>  
</div>

<? } else { ?>

<div id="main-content-container" class="grid_13">
    <div id="main-content-inner">
        <?php
        $a = new Area('Main');
        $a->display($c);
        ?>          
    </div>  
</div>

<? } ?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongnong3019 dongnong3019 2012-04-26 13:05

    While your content generation portions of PHP use proper PHP tags (<?php … ?>), your if/else statements use short tags (<? … ?>) which are often disabled.

    Use <?php instead.

    点赞 评论 复制链接分享
  • dongyue934001 dongyue934001 2012-04-26 13:11

    try to do like this may this will solve the issue

    <?php if($c->getNumChildren()!='') { ?> ... <?php } else { ?> ... <?php } ?>

    点赞 评论 复制链接分享

相关推荐