views:

290

answers:

2

hi,

I have a kohana v3 app. 2 subdomains pointing to this app. what I have to setup that kohana uses a different template if the app called with subdomain2.example.com?

at the moment all calls (from subdomain1 and subdomain2) use the standard template: 'templates/default'

thank you!

daniel

A: 

may anybody can help me: http://stackoverflow.com/questions/2764543/kohana-v3-using-different-templates-for-different-subdomains

danzzz, there are a few ways... (i dont have time to go into detail.. so i'll give a quick go here..) .. A) use URL rewriting to map bla.site.com to site.com/bla (and www.bla.com+bla.com to bla.com/www) ... use that first param as the trigger... then load a different module at the top of the stack so it can override anything from a lower module - this assumes anything that is overridable is kept in a module, otherwise, you can use it as a trigger any where in the code... and B) is really the same thing, but using that param as the view name or similar... whenever i have something like that, i tend to leave my application folder empty, and have an application module near the top of the module stack.. that way, i can load a "skin" module higher up and have the cascading FS do all the hard work... keep in mind that "skin" modules etc will need a strict set of rules and interfaces, if you make a change to the app, you need to know all the skins still work...

Kiall
IRC nicks and formatting stripped ;) ah well - hopefully it still makes sense to anyone else reading it..
Kiall
+2  A: 

First, get the subdomain name from $_SERVER['SERVER_NAME']:

list($subdomain) = explode('.', $_SERVER['SERVER_NAME'], 2);

Then choose what template to use based on the subdomain:

// Replace this with a switch() statement if you want to choose another way
$this->template = 'templates/'.$subdomain;

The above code should be placed in the Controller::before() method before you call parent::before(). This assumes that you are using the Controller_Template or an extension of it.

shadowhand