Page 1 of 1
Change theme based on domain name
Posted: Wed Feb 03, 2010 9:02 am
by decavolt
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.
Re: Change theme based on domain name
Posted: Wed Feb 03, 2010 9:05 am
by imaginetech
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.
Re: Change theme based on domain name
Posted: Thu Feb 04, 2010 7:56 am
by decavolt
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.
Re: Change theme based on domain name
Posted: Thu Feb 04, 2010 11:01 am
by imaginetech
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.
Re: Change theme based on domain name
Posted: Thu Feb 04, 2010 11:28 am
by decavolt
No. This doesn't touch the db at all.
Re: Change theme based on domain name
Posted: Thu Feb 04, 2010 12:32 pm
by imaginetech
Sorry, was reading on the iphone and the code snippet was truncated.
Looks good.