Yii && Many Template (Themes)

Hi yii experts !

I developped an application with Yii that allow user to choose one of template (themes) sthat exist in the application,

he can swith the template whenever hewants, but my solution seems to be limited.

I explain my solution :

For example i have 5 templates to include to my application, and i have a "News" crud (NewsController and its views), so i create in views folder 5 folders that are related to NewsController :

  • folder 1 :theme2_news

  • folder 2 :theme2_news

  • folder 3 :theme3_news

  • folder 4 :theme4_news

  • folder 5 :theme5_news

and when i want to swicth from one theme to an other, i do like that :


$this->render("/themex_news/create")

I tried this solution and it’s great, but the problem is that when i want to add many templates (themes) i must create for each controller it’s view, and when the number of template become big, the view folder will have thounds of folders.

I took a look to Yii Theming but it seems to me more limited then my solution.

Is there any ideas ??

Thanx !

Why do you need to copy the view files? Do you know you can use themes with ONE set of view files?

Are the contents of the files radically different?

I have a site with multiple themes and the only thing thats different is the css and image files for that theme (and layout, actually).

well for dynamic contnent it’s actually the same, but the problem is that the design (divs and tables) are completely different. every theme must have a different design to the other.

That’s why i poied the views folders, so inevery view i can put its costomized Html (same thing for layouts)

Looking in Yii Theming i descovered the same thing :

  • every theme has his own folder and its own views… or i’m wrong ?

Its not necessary to change the controllers and views code!

set generally the rendering


$this->render("create")



And set the theme by each user configuration like that:

in your protected/component/controller.php set the bellow method


public function render($view,$data=null,$return=false)

	{	

                $thetheme='usertheme';

		Yii::app()->setTheme($thetheme);

		return parent::render($view,$data,$return);

	}

if It is necessary set different css for each theme

You didn’t answer my question.

Of course your layouts may be different for different themes. But are your View files actually different?

well yes actually the html for views is completely different between one theme and another so that’s why i have to change the html of each view. But for dynamic content that is passed from controller it’s the same.