Search code examples
phpthemesconditional-statementsconcrete5

My PHP condition statement display two results for if and else, what's wrong my my code?


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>

<? } ?>

Solution

  • 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.