In opencart 2.2 product.tpl file I found the following code which is quite confusing to me:
<div class="row" style="padding-top:10px"><?php echo $column_left; ?>
<?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 } ?>
Specifically, I'm not able to understand how they can use ?> inside curly brackets of if statement? More important, I tried to revise the above code as following but then it stopped working:
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) {
$class = 'col-sm-6';
}
elseif ($column_left || $column_right) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
?>
Any explanations?
if
is required, otherwise you'll get an error. As for the per line<?php
and?>
, it's down to the developer, and is valid either way.