I am creating an responsive template and for that to happen I need to use and if else and function. This is what I have so far.
<?php if ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
I am now receiving the error:
Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND) in index.php on line 197
Line 197 =
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
I have tried adding an extra () but that did not work:
<?php } elseif (($this->countModules('left')) && ($this->countModules('right'))) { ?>
I am forgetting something but what.
The order is wrong and instead of adding the () you should remove a set. See the adapted code below.
<?php if ($this->countModules('left') && $this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
Hopefully this puts you in the right lane.
You have your brackets in the wrong place. Try replacing the following:
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
with this:
<?php } elseif ($this->countModules('left') && $this->countModules('right')) { ?>
Related
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?
There is no mistake in the php code.
You can open and close a php tag as much as you like. During run time the files are processed and all the php code is interpreted each line at a time.
So it is fine to write like this
<?php echo 'hello';
echo 'world';
?>
as well as this
<?php echo 'hello'; ?>
<?php echo 'world'; ?>
The only reason why OpenCart uses the later style is becuase it is a bit nicer since the <?php tag creates a column and is a bit easier to read.
Its clearly visible, there is syntax error for if. You can't use elseif without if.
<?php
if ($check) {
// Code...
} elseif ($check_2) {
// Code...
}
?>
<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';
} // this is missing in your case
?>
<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';
} // you have missed this "}" for the else .
?>
I am trying to implement below code from here in catalogue/view/theme/default/template/checkout/confirm.tpl
<?php if ($this->cart->getSubtotal() >= 1000) { ?>
<div id="payment"><?php echo $payment; ?></div>
<?php } else { ?>
<div class="warning">Minimum 10 Euro to checkout</div>
<?php } ?>
but i am getting an error
Notice: Undefined property: Loader::$cart in C:\xampp\htdocs\optest\catalog\view\theme\default\template\checkout\confirm.tpl on line 51
Fatal error: Call to a member function getSubtotal() on null in C:\xampp\htdocs\optest\catalog\view\theme\default\template\checkout\confirm.tpl on line 51
reference taken:
Opencart minimum order price exclude one category
http://forum.opencart.com/viewtopic.php?t=53810
Not the same way but you can do it like this:
Add this line in your checkout.php controller file.
if ($this->cart->getSubtotal() < 1000) {
$this->session->data['error'] = 'Your warning message';
$this->response->redirect($this->url->link('checkout/cart'));
}
After
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
Thats it.
The code below is working for me:
<?php if($this->session->data['currency'] == 'USD') : ?>
<?php if($this->cart->getSubtotal() < 2enter code here0) : ?>
<div class="warning"><center><?php echo $text_comandamin_eur; ?></center></div>
<?php endif; ?>
<?php } elseif($this->session->data['currency'] == 'INR') : ?>
<?php if($this->cart->getSubtotal() < 1000) : ?>
<div class="warning"><center><?php echo $text_comandamin_ron; ?></center></div>
<?php endif; ?>
<?php endif; ?>
On my codeigniter project with HMVC on my view page the $class is not showing correct one. When I try to view my modules if there is no column left or right it should go to col-sm-12
For some reason it shows col-sm-9 when it should be col-sm-12 if no column left or right.
<?php echo $header; ?>
<div class="container">
<div class="row"><?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 } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?><?php echo $content_bottom; ?></div>
<?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?>
How can I make it display col-sm-12 if no column-left or column-right?
Thanks in advance.
Added Controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends MX_Controller {
public function index() {
$data['column_left'] = Modules::run('catalog/common/column_left/index');
$data['column_right'] = Modules::run('catalog/common/column_right/index');
$data['content_top'] = Modules::run('catalog/common/content_top/index');
$data['content_bottom'] = Modules::run('catalog/common/content_bottom/index');
$data['footer'] = Modules::run('catalog/common/footer/index');
$data['header'] = Modules::run('catalog/common/header/index');
return $this->load->view('theme/default/template/common/home_view', $data);
}
}
You don't need to put those thousand php opening and closing tags.
<?php
if (!empty($column_left) && !empty($column_right)) {
$class = 'col-sm-6';
} elseif (!empty($column_left) || !empty($column_right)) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
}
?>
UPDATED
Remove return from this statement
return $this->load->view('theme/default/template/common/home_view', $data);
This should be :
$this->load->view('theme/default/template/common/home_view', $data);
elseif(empty($column_left) || empty($column_right)){ ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
If $column_left or $column_right is set then it will never reach the last else part. Just check with !empty(). It will check if the value is empty or not.
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif (!empty($column_left) || !empty($column_right)) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
I found out what problem was it was most simplest thing I had forgotten the to add the id on my column left and right
And thanks to #tiGer of the remove return also helped
Column Left Module
<?php if ($modules) { ?>
<column id="column-left" class="col-sm-3 hidden-xs">
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</column>
<?php } ?>
Column Right
<?php if ($modules) { ?>
<column id="column-right" class="col-sm-3 hidden-xs">
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</column>
<?php } ?>
I am using this code for Condtion but I dont know why the condtion is going False
<tr
<?php if ($LevelName['Status'] == 'Yes') { ?>
style="background:#DCFEB7"
<?php } ?>
<?php elseif (strtotime(date('Y-m-d h:i')) > strtotime($LevelName['ReportTime'])) { ?>
style="background:red"
<?php } ?>
<?php else { ?>
style="background:orange"
<?php } ?>
>
I don't know why the backgound color not going to Red
getting this result in condition:
(Todat Date)392291420 > (DB Date)1392336360
Here's my php code:
<?php if($user->uid == '1'){ ?>
<h3 class="info">Upcoming Games</h3> <!--MY CHANGE -from Athletics Events -->
<?php } ?>
<?php else { ?> <h3 class="info">Athletic Events</h3> <?php }?>
Why do I get this error? I have all the brackets I need, don't I?
The } and else { can't be broken apart with PHP tags the way that you have it. Think of it as if you were trying to do:
<?php
if($some_condition) {
//do something
}
echo ' ';
else {
//something else
}
This would give you a parse error. Because you are closing the PHP tags, and then effectively outputting whitespace, then reopening, your code is behaving similarly to this. The same also applies if you were to be doing <?php }?><?php else {?> as well, only it would behave like you were doing echo ''; in between.
A cleaner and less error prone way is to use :
<?php if($user->uid == '1'): ?>
<h3 class="info">Upcoming Games</h3> <!--MY CHANGE -from Athletics Events -->
<?php else: ?>
<h3 class="info">Athletic Events</h3>
<?php endif; ?>
Try it like this
<?php if($user->uid == '1'){ ?>
<h3 class="info">Upcoming Games</h3> <!--MY CHANGE -from Athletics Events -->
<?php } else { ?> <h3 class="info">Athletic Events</h3> <?php }?>
Rewrite like this and let's see
<?php if($user->uid == '1'){ ?>
<h3 class="info">Upcoming Games</h3> <!--MY CHANGE -from Athletics Events -->
<?php
} else {
?>
<h3 class="info">Athletic Events</h3>
<?php
}
?>
this also worked
<?php if($user == '1'){ ?>
<h3 class="info">Upcoming Games</h3> <!--MY CHANGE -from Athletics Events -->
<?php } else ?>
<?php { ?> <h3 class="info">Athletic Events</h3> <?php }?>
that was a replica of your code but the else is move up. So it is obvious else should not be at the start