Cascading theme


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?

Thanks in advance.

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 :rolleyes:

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.

Thanks for the try anyway.

you can have trillion of themes, I don’t understand the problem :mellow:

The "base theme" is your view and all other is themes

I need the application search a view in other theme if it didn’t find the view in the first one.

Go it! And is f***ing easy xD

Only changed the application viewPath to the folder I have the "base theme".

Thanks for trying to help me.

Unfortunately this is not completely solved…

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:


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:


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.

Thanks in advance.

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.

I can’t believe that the possibility of cascading any number of themes isn’t a built-in feature in the framework (yet!).

Please somebody tell me it is and I am missing it.