duanpu6319 2014-07-18 06:07
浏览 25
已采纳

在OpenCart的内容框中添加动态类

I am working on OpenCart 1.5.6.4. I want to add dynamic CSS class in content box. I want the following options for the content box layout:

  • left panel + main content + right panel
  • only left panel + main content
  • only main content + right panel
  • only main content (without left & right panels)

With the following code each case except the main content + right panel is working:

 <?php if ($column_left && $column_right) { ?>
    <?php $class = 'col-sm-6'; ?>
    <?php } elseif ($column_left || $column_right) { ?>
    <?php $class = 'col-sm-9'; ?>
    <?php } else { ?>
    <?php $class = 'col-sm-12'; ?>
    <?php } ?>
    <div id="content" class="<?php echo $class; ?>">.....</div>

I get this results: enter image description here

What is wrong here with the last option? How can I fix it?

Would appreciate the help.

  • 写回答

1条回答 默认 最新

  • drnysdnnb2909701 2014-07-18 09:04
    关注

    Your code looks completely fine and should be working. The reason it seems it is not is because most probably you have some data in the $column_left even if it should be empty (thus considered as false).

    The best bet is to either check the $column_left variable when there should be only main content + right column displayed (print_r($column_left)) or check the left column's template immediately (catalog/view/theme/<YOUR_THEME>/template/common/column_left.tpl).

    Normally the code in column_left.tpl should be

    <?php if ($modules) { ?>
    <div class="column_left">
        <?php /* ... */ ?>
    </div>
    <?php } ?>
    

    It is possible that You have something like this instead:

    <div class="column_left">
    <?php if ($modules) { ?>
        <?php /* ... */ ?>
    <?php } ?>
    </div>
    

    therefore there is empty <div> and your code correctly uses col-sm-6 for main content.

    After fixing the column_left.tpl you should have col-sm-9 for main content + col-sm-3 for right column if there is no left column data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境