Kohana::modules(array(
// ... All enabled modules
'my_theme' => DOCROOT.'themes/my_theme'
));
Kohana::modules(Kohana::modules() + array(
'theme' => DOCROOT.'themes/my_new_theme'
));
I'm using the template controller, could that have anything to do with it?
I doubt it.
What Olly described above still requires you to to put your views within a folder called 'views' inside the theme folder. The theme folder here is just a kohana module (ie. can contain classes, views, configs etc).
So your view files should be like
themes/my_new_theme/views/template.php
Hi
I never really liked making a theme a module; I don't want my app looking for classes in the theme folder. Also it seems a bit hackish to run Kohana::modules() after the bootstrap just to get the theme path at the top of the cascade. This also means all the modules init.php files would be run twice.
(You could also implement something like a Kohana::add_module() to achieve this, but still with the classes issue. I'd like to be able to create "downloadable themes" scenario without the risk of classes overriding my app.)
I over-ride the View set_filename() method as below. nb. my themes are activated in the config and can be switched per user session, if authorised.
class View extends Kohana_View {
public function set_filename($file)
{
$session = Session::instance();
if ($theme = $session->get('theme'))
{
$theme_file = Kohana::config('theme.path').$theme.'/views/'.$file.EXT;
if (is_file($theme_file))
{
$this->_file = $theme_file;
return $this;
}
}
try
{
return parent::set_filename($file);
}
catch (Kohana_View_Exception $exception)
{
throw $exception;
}
}
}
I do similar (cascade) within my Assets class for js, css, images etc..
$theme_name = 'my_theme'; //This would be grabbed from the database
if( kohana::find_file('views', $theme_name.'/view_name') ){
// Load from my_theme as file exists
$this->template = new View($theme_name.'/view_name');
}else{
$this->template = new View('default/view_name');
}
It looks like you're new here. If you want to get involved, click one of these buttons!