I have a situation where I need to have two themes. The first theme, I will call it the front theme. The second one, I’ll call it the base theme.
What I need is… when I call render function, the application will search for the view in the front theme, and if the view doesn’t exist, the application will render the view in the base theme.
What do you think that is the best way to do that?
Themes work like this - when you set a them, it will search for a view in the theme, if it not exists, it will go to view directory in main app, and will search there.
So this is the solution
Just create fronTheme directory in themes set it in main.php and than it will search in them if not found go to app view
Yes, I know it. But the problem is that I need specify the base theme. It could exist many base themes, and with the application default behavior, I can only have one.
Anyone have a simple idea to implement cascading view search? By other words, I have the following themes with views:
Theme A (level 1)
index.php
Theme B (level 2)
index.php
login.php
I need to call view index.php:
$this->render(‘index’);
The application looks for the view index in the theme level 1. Yes, exist, render this view of theme level 1.
Now I need to call the view login.php:
$this->render(‘login’);
The application looks for the view login in the theme level 2. No, it isn’t exist, so it looks for the login view in the next theme level, level 2. Yes, exist, render this view of theme level 2.
This is very similiar to the default application behavior, that looks for a view in the theme directory and if this not exist, looks for it in the protected/views directory. The difference is that I need to specify 2 themes to look for.
Since this isn’t the default behavior, you’ll have to extend Controller and override the getViewFile method. You can see the source here: getViewFile source
Any controller you create would have to extend your new controller to access your version of getViewFile.