2
votes

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
When you have only the right column and it should be col-sm-9 + col-sm-3 please check (print out) the $column_left - obviously it is not empty (it may contain some empty <div> for example) or even check the catalog/view/theme/<YOUR_THEME>/template/common/column_left.tpl template...shadyyx
Here, not issue in right & left column. but, I want to add class col-sm-9 in main content when layout only main content + right panel. but, Here, I get class col-sm-6 in main content.HDP
I know what is the problem and therefore I am asking you to check the $column_left variable (or it's template) when only column right + main content should be there...shadyyx
Thank You so much. solved issue. It was space issue add of code in $column_left file.HDP
OK, will write an answer for this so that You can accept it.shadyyx

1 Answers

1
votes

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.