Theme Based Layouts, How?

Hey guys!

I have a simple question, and I can’t figuring out the answer from the documentation.

Is there any way to define different layouts for controller actions, depending on which theme is currently active?

Let’s say I have an active theme named ‘theme_1’, a ‘customer/login’ view and a ‘main’ layout.

Later I want to change from ‘theme_1’ to ‘theme_2’, which has two different layouts named ‘main’ and ‘other’.

How can I tell yii (in the proper way of course) to use the ‘other’ layout when ‘theme_2’ is active, and ‘main’ layout in other cases.

Thank you in advance!

Dani

try this, if it’s working, credit goes to @Dana.

it does work with module specified theme (i tried), i would assume it work for controller-specified too.

Hey rootbear!

Thank you for you reply, but I’m afraid you didn’t understand my problem.

Theming a whole module is different from what I want, because in that case you define a new theme for the whole module, no matter what.

What I want to tell Yii is something like this:

  • Dear customer controller! Use layout ‘3col’ for your login view if the current theme is ‘theme_1’, because it will look pretty!

  • In any other cases (theme_2,theme_3) you should leave the layout on default (main for example).

Can’t you just change the layouts with same name in different themes? Or make wrapper layouts that call some other layout and make those different in each theme?

i got your question. that’s why i said: “i would assume it work for controller-specified theme too.

you may want to try this in your controller.


public function init()

{

Yii::app()->theme = 'theme_2';

}

OK, I read your question again.

I would suggest use same name as layout for the same view in different themes, why bother to mess around layout name at view level?

if you don’t like the default layout name, like ‘column1’ ‘column2’ you can create on called ‘my-very-unique-layout-name’ and have it in both themes with different design.

is that the whole purpose you use different themes?

Thank you for your reply!

The reason for ‘messing around with layouts in view level’ is that it is possible, that for example a product grid view in a webstore is using a 3 column layout (in theme_1), but if the user decide to switch to another theme (theme_2), which has its multiple layout types (including a 3 column one), BUT maybe in that theme the product grid view is prettier with 1 column layout, than with 3. Hope I explained it well and it do makes sense :)

Otherwise your idea is good, it seems to me that the best idea is to make multiple layouts with the same name for each theme like login_layout, product_details_layout, etc.

thanks,

i agree, manage layouts at theme/layouts side is better than having the logic in controller/view,

so layout ‘product1’ has 3 columns in ‘theme_1’

while layout ‘product1’ has 2 columns in ‘theme_2’

please see forum

i hope it’s some help