Post by decavolt » Wed Feb 03, 2010 9:02 am

How can I change themes based on the domain name used? Is there any way for me to change config_template on the fly, based on the URL?
I've found

Code: Select all

$this->template = $this->config->get('config_template') . 'common/layout.tpl';
and know that this is set within the Admin settings. How would I go about overriding this? Ideally, I'd do something like

Code: Select all

if ($_SERVER['HTTP_HOST'] == 'foo.com') {
$config_template = 'foo';
} else {
$config_template = 'bar';
}
in order to set config_template site wide.

This is similar to a reply I posed here but I thought this deserved its own thread.

Newbie

Posts

Joined
Tue Aug 18, 2009 9:35 am

Post by imaginetech » Wed Feb 03, 2010 9:05 am

I'm interested in this too.

Maybe one way would be to have the config_template var stored in the session data allowing it to be overridden when needed.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia

Post by decavolt » Thu Feb 04, 2010 7:56 am

I think I may have found a solution to this...

In system/library/config.php I've changed:

Code: Select all

public function get($key) {
	return (isset($this->data[$key]) ? $this->data[$key] : NULL);
}	
to

Code: Select all

public function get($key) {
	if ($key == 'config_template') {
		if ($_SERVER['HTTP_HOST'] == 'example.com') {
			$usetemplate = 'foo/template/';
		} else {
			$usetemplate = 'bar/template/';		
		}  		
		return $usetemplate;
	} else {
  	return (isset($this->data[$key]) ? $this->data[$key] : NULL);			
	}
}
where "foo" and "bar" and separate themes.

I also edited /config.php to allow for two domains:

Code: Select all

// HTTP
if ($_SERVER['HTTP_HOST'] == 'example.com') {
	define('HTTP_SERVER', 'http://example.com/');
	define('HTTP_IMAGE', 'http://example.com/image/');
} else {
	define('HTTP_SERVER', 'http://otherdomain.com/');
	define('HTTP_IMAGE', 'http://otherdomain.com/image/');
}
Otherwise every link will be directed back to the original domain.

I haven't fully tested this, but so far it seems to be working and saves me from having to edit every single controller.

Newbie

Posts

Joined
Tue Aug 18, 2009 9:35 am

Post by imaginetech » Thu Feb 04, 2010 11:01 am

Question: aren't you just changing the db value though? If you are then the next person that visits the other domain will just reset it the value and on your next refresh you'll see what they see.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia

Post by decavolt » Thu Feb 04, 2010 11:28 am

No. This doesn't touch the db at all.

Newbie

Posts

Joined
Tue Aug 18, 2009 9:35 am

Post by imaginetech » Thu Feb 04, 2010 12:32 pm

Sorry, was reading on the iphone and the code snippet was truncated.

Looks good.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia
Who is online

Users browsing this forum: No registered users and 5 guests