Post by SamLar » Wed Dec 23, 2009 9:04 am

Hey guys,

not sure if I'm in the right category in here. Basically I would like to know how it works to move code from one template to another - let's say - the navigation code in the header.tpl (div class 4) to let's say into column_left.tpl.

I guess it has something to do with some scope setup? Because it doesn't really work and it brings up some variable undefined errors. Take this as a generic question to move bits around templates.

Anyone knows how to do or what's the best practice here?

cheers in advance,
sam

New member

Posts

Joined
Tue Dec 22, 2009 2:20 pm

Post by moggiex » Wed Dec 23, 2009 9:30 am

heya Sam,

This can be readily done, however you must be aware that the functions that are controller header.php file are most likely to be different to those in the module controller file you're playing with.

So.... make sure you nick the relevant function parts from the header.php controller file and put it in the module controller file you are playing with.

A good example of this is that I was annoyed by duplicate urls in OpenCarts structure, the homepage is one of them and while I was at it, I abused the image server to deliver content separely, buy adding/replacing the following in the header.php file to the other controller files, such as a category.php and product.php, I was able to use two vars, $base and $base_image for the image paths and site links, so that they link back to the single place and images are delivered from a consistent content subdomain.

Code: Select all

if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$this->data['base'] 		= HTTPS_SERVER;
			$this->data['base_image'] 	= HTTPS_IMAGE;
		} else {
			$this->data['base'] 		= HTTP_SERVER;
			$this->data['base_image'] 	= HTTP_IMAGE;
		}
Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by SamLar » Wed Dec 23, 2009 12:46 pm

Awesome Matt.
Didn't try it yet but will do soon.

thx buddy
cheers,

New member

Posts

Joined
Tue Dec 22, 2009 2:20 pm

Post by huhitschris » Fri Dec 25, 2009 5:50 am

Similar to what Matt said,

Open "opencart\catalog\controller\common\header.php"

Copy the statements which define the variables you need for the page, for example:

Code: Select all

$this->data['text_home'] = $this->language->get('text_home');
$this->data['text_special'] = $this->language->get('text_special');
$this->data['text_account'] = $this->language->get('text_account');
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_logout'] = $this->language->get('text_logout');
$this->data['text_cart'] = $this->language->get('text_cart'); 
$this->data['text_checkout'] = $this->language->get('text_checkout');

$this->data['home'] = $this->url->http('common/home');
$this->data['special'] = $this->url->http('product/special');
$this->data['account'] = $this->url->https('account/account');
$this->data['logged'] = $this->customer->isLogged();
$this->data['login'] = $this->url->https('account/login');
$this->data['logout'] = $this->url->http('account/logout');
$this->data['cart'] = $this->url->http('checkout/cart');
$this->data['checkout'] = $this->url->https('checkout/shipping');
These are all variables which can be used on the file "header.tpl", so...

$this->data['home'] on header.php in controller

is referenced by...

$home on header.tpl in view templates

So, the next step is to get these variables into the left column...

Open "opencart\catalog\controller\common\column_left.php" and copy and paste the variable declarations from the home.php file.

Now open "opencart\catalog\view\theme\default\template\common\column_left.tpl" and copy your "div4" code from header.tpl into the column_left template file.

Now your column_left template will be referencing defined variables and should start working correctly. There may be a few more things you'll want to carry over but this is basically the process.

I really hope that didn't get too confusing, let me know how it works out for ya.

-Chris

PM me for custom OpenCart template design and development.


New member

Posts

Joined
Wed Aug 19, 2009 3:12 pm
Who is online

Users browsing this forum: No registered users and 1 guest